Public · Protected · Private
Dynamic Dispatch
Type: Public  |  Created: 2012-08-29  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • 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

    2012-08-29 14:49
This blog is frozen. No new comments or edits allowed.