I need to build some classes dynamically and save the assembly
to disk,however when I examine a dynamically built class
using ildasm, and compare it with a statically built class
with the same member structure, I realized that the
manifest of dynamically built ones seem to be cut off,
I mean that its manifest is much simpler, besides when
statically referencing the dynamically generated dll from
another program class members don't show. Here is a snippet
with 2 very simple and identical classes one built
statically and the other dynamically to compare their manifest.
I cant figure out what is wrong, please can someone help me?
public class SimpleClass
{
public string Name;
public int Age;
}
class Program{ static void Main(string[] args) { AppDomain appDomain = AppDomain.CurrentDomain; AssemblyName aName = new AssemblyName(); aName.Name = "SimpleReflection"; AssemblyBuilder assemBuilder = appDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Save); ModuleBuilder modBuilder = assemBuilder.DefineDynamicModule(aName.Name,"SimpleDyn.dll"); TypeBuilder tb = modBuilder.DefineType("SimpleDyn.SimpleClass1", TypeAttributes.Public | TypeAttributes.BeforeFieldInit, typeof(object)); FieldBuilder field1 = tb.DefineField("Name", typeof(string), FieldAttributes.Public); FieldBuilder field2 = tb.DefineField("Age", typeof(int), FieldAttributes.Public); tb.CreateType(); assemBuilder.Save("SimpleDyn.dll"); } }
↧
building and saving an assembly dinamically
↧