Dynamically add properties to a existing object

后端 未结 7 1328
说谎
说谎 2020-12-01 13:49

I create the person object like this.

 Person person=new Person(\"Sam\",\"Lewis\") 

It has properties like this.

person.Dob         


        
7条回答
  •  囚心锁ツ
    2020-12-01 14:24

    Take a look at the Clay library:

    http://clay.codeplex.com/

    It provides something similar to the ExpandoObject but with a bunch of extra features. Here is blog post explaining how to use it:

    http://weblogs.asp.net/bleroy/archive/2010/08/18/clay-malleable-c-dynamic-objects-part-2.aspx

    (be sure to read the IPerson interface example)

提交回复
热议问题