Dynamic Dispatch

quick dynamic code

dynamic a = 12;
dynamic b = "hi";
dynamic c = DateTime.Now;

 

sample expando class

public class simpleExpando : DynamicObject
{
    Dictionary<string, object> items = new Dictionary<string, object>();
       
    private string _Name;
    public string Name
    {
        get{return _Name;}
        set{_Name = value;}
    }
    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
        return items.TryGetValue(binder.Name, out result);
    }

    public override bool TrySetMember(SetMemberBinder binder, object value)
    {
        items[binder.Name] = value;
        return true;
    }
}

using the expando class

dynamic kgg = new simpleExpando();
kgg.lll = "12";
MessageBox.Show(kgg.lll);
kgg.myproperty1 = "myproperty1";
kgg.myproperty2 = "myproperty2";
kgg.myproperty3 = "myproperty3";
kgg.llll = 16;v