Search code examples
c#reflectiondynamicsilverlight-4.0dynamic-class-creation

Create Dynamic class at runtime


can any body have idea for create dynamic class at run time.i have one dictionary<string,object> which is contains datatable's all columns with it's datatype my plan is to create a dynamic class base on dictionary. means datatable's column name is property of class. after create list<dynamic class> and bind to grid

it's grate help if you have code for it


Solution

  • meta-programming on Silverlight is fairly limited, but TypeBuilder is probably what you are looking for. An easier option, though, is to use ExpandoObject and dynamic, but frankly: you might as well just use the dictionary. I'm not sure I'd bother going to the trouble of meta-programming for this.

    If you do go that route, you can get a new empty list via:

    IList list = (IList)Activator.CreateInstance(
           typeof(List<>).MakeGenericType(newType));