dynamic 使用

            dynamic a = new { A = , B =  };
Console.WriteLine("a.A=" + a.A); dynamic b = new Dictionary<string,int>();
b["A"] = ;
Console.WriteLine("b[\"A\"]=" + b["A"]);
//Following opration is not supported
//b.A=6;
//Console.WriteLine("b[\"A\"]=" + b.A); var c = func();
Console.WriteLine("c[0].A=" + c[].A);
//Access c[0].UnknowProperty will cause a RuntimeBinderException dynamic test = new TestClass();
test.P1 = ;
test.P2 = func();
Console.WriteLine("test.P1=" + test.P1);
Console.WriteLine("test.P2[1].B=" + test.P2[].B); static dynamic[] func()
{
return new dynamic[]{new
{
A = ,
B =
},new
{
A = ,
B =
}};
} public class TestClass
{
public int P1 { get; set; } public dynamic P2 { get; set; }
}
    [Serializable]
public class DynamicObject : IDynamicMetaObjectProvider
{
protected DynamicObject(); public virtual IEnumerable<string> GetDynamicMemberNames(); public virtual DynamicMetaObject GetMetaObject(Expression parameter); public virtual bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result); public virtual bool TryConvert(ConvertBinder binder, out object result); public virtual bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result); public virtual bool TryDeleteIndex(DeleteIndexBinder binder, object[] indexes); public virtual bool TryDeleteMember(DeleteMemberBinder binder); public virtual bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result); public virtual bool TryGetMember(GetMemberBinder binder, out object result); public virtual bool TryInvoke(InvokeBinder binder, object[] args, out object result); public virtual bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result); public virtual bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value); public virtual bool TrySetMember(SetMemberBinder binder, object value); public virtual bool TryUnaryOperation(UnaryOperationBinder binder, out object result);
}
上一篇:实现AJAX的异步交互的步骤


下一篇:AutoCompleteTextView,Spinner,消息提示