0

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

Chirag
  • 375
  • 4
  • 30
  • 1
    Maybe you should ready about `ORMs` like `EntityFramework` or `nHibernate` because it looks like you're trying to do this on you own. – Piotr Auguscik Feb 08 '12 at 09:34

1 Answers1

2

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));
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 1
    @Chirag I've linked to MSDN; MSDN has a full example (for Silverlight). The code to create types at runtime is... not brief. – Marc Gravell Feb 08 '12 at 09:46