Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
dynamic a = 2;
dynamic b = 3;
dynamic c = a + b;
dynamic x = 2;
dynamic y = 3;
int c = x + y;
long d = x + y;
var rObj = (IRemoteCom)Activator.GetObject(typeof(IRemoteCom),"tcp://localhost:1002/Test");
rObj.DoSomething();
dynamic dObj = (IRemoteCom)Activator.GetObject(typeof(IRemoteCom),"tcp://localhost:1002/Test");
dObj.DoSomething();
public class DynamicProxy : System.Dynamic.DynamicObject
{
private readonly object _instance;
public DynamicProxy(object instance)
{
_instance = instance;
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
if (binder.Name == "DoSomething")
{
var objType = _instance.GetType();
var remoteInterface = objType.GetInterface("IRemoteCom");
var method = remoteInterface.GetMethod("DoSomething");
result = method.Invoke(_instance, args);
return true;
}
result = null;
return false;
}
}
public class Tocken
{
public TockenType Type { get; private set; }
public object Value { get; private set; }
public Tocken (object Value, TockenType Type)
{
this.Value = Value;
this.Type = Type;
}
}
public class Node
{
public NodeKind Kind;
public Object Value;
public List<Node> Nodes;
public Node (NodeKind Kind, Node Value, List<Node> Nodes)
{
this.Kind = Kind;
this.Value = Value;
this.Nodes = Nodes;
}
public Node (NodeKind Kind, Object Value)
{
this.Kind = Kind;
this.Value = Value;
this.Nodes = new List<Node>();
}
public void Write (int depth)
{
for (int i = 0; i < depth; i++)
Console.Write ('|');
Console.Write ('+' + Kind.ToString ().ToUpper ());
if (Value != null)
if (Value.GetType () == typeof(Node)) {
Console.WriteLine();
(Value as Node).Write (depth + 1);
} else {
if (Value != null)
Console.Write("={1}", Kind.ToString ().ToUpper (), Value.ToString ());
}
foreach (Node n in Nodes) {
Console.WriteLine();
n.Write(depth + 1);
}
if(depth == 0)
Console.WriteLine();
}
}
def a = 5
строилось около 3 секунд вместо где-то четверти секунды…
Погружаемся в глубины C# dynamic