views:

210

answers:

2

Is it possible to use Reflection.Emit to create types in an existing assembly, or do you need to define a new dynamic assembly to be able to contain dynamic types?

Basically, I intend to read in one XML definition file which defines a class that is then instantiated multiple times and populated with the data from several other XML files. Rinse and repeat over several folders (each with a different definition file).

I also intend to use this data to dynamically build the interface to my app as well as define how the data is formatted when re-saving the data to the XML files.

+1  A: 

Using Reflection.Emit, you define a new assembly.

Cheeso
+2  A: 

When using Reflection.Emit, you must always create a new assembly.

However, one potential option is to take your existing assembly, and define the contracts as interfaces. You can create the new assembly at runtime with Reflection.Emit, and have it define types that implement your interfaces. Your assembly can use a factory pattern to instantiate the property, dynamically generated type, and return an implementation of your (known at compile time) interface.

Reed Copsey
I think this is the answer I need, but are you basically suggesting that I use interfaces as a form of programmatic Lego blocks? Because the only other way I can think of using interfaces in this part of the project would require them to be dynamic as well...
EvoGamer
Yes, that was the basic idea. You need to define your contracts with interfaces, and use the dynamnic generation to "glue" your program together via the interfaces.
Reed Copsey