M
Moe Green
I want create a method which uses a dynamically enum as the type of one
of its parameters.
I can create the assembly with this code:
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "EmittedAssembly";
// Create the dynamic assembly.
myAssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAssemblyName,
AssemblyBuilderAccess.Save);
// Create a dynamic module.
myModuleBuilder =
myAssemblyBuilder.DefineDynamicModule("EmittedModule",
"EmittedModule.mod");
// Create a dynamic Enum.
myEnumBuilder = myModuleBuilder.DefineEnum("MyNamespace.MyEnum",
TypeAttributes.Public, typeof(Int32));
FieldBuilder myFieldBuilder1
= myEnumBuilder.DefineLiteral("FieldOne", 1);
FieldBuilder myFieldBuilder2
= myEnumBuilder.DefineLiteral("FieldTwo", 2);
myEnumBuilder.CreateType();
myAssemblyBuilder.Save("Ass1.dll");
But, how do I access this in a method.
I want to do something like
class blah {
myMethod( NyNamespace.MyEnum e)
{
...
}}
But it will not let me use this or
void method(a.GetType("MyNamespace.MyEnum") b)
{
}
How can I use an enum in an emitted assembly to define the input
parameter of a method?
of its parameters.
I can create the assembly with this code:
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "EmittedAssembly";
// Create the dynamic assembly.
myAssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAssemblyName,
AssemblyBuilderAccess.Save);
// Create a dynamic module.
myModuleBuilder =
myAssemblyBuilder.DefineDynamicModule("EmittedModule",
"EmittedModule.mod");
// Create a dynamic Enum.
myEnumBuilder = myModuleBuilder.DefineEnum("MyNamespace.MyEnum",
TypeAttributes.Public, typeof(Int32));
FieldBuilder myFieldBuilder1
= myEnumBuilder.DefineLiteral("FieldOne", 1);
FieldBuilder myFieldBuilder2
= myEnumBuilder.DefineLiteral("FieldTwo", 2);
myEnumBuilder.CreateType();
myAssemblyBuilder.Save("Ass1.dll");
But, how do I access this in a method.
I want to do something like
class blah {
myMethod( NyNamespace.MyEnum e)
{
...
}}
But it will not let me use this or
void method(a.GetType("MyNamespace.MyEnum") b)
{
}
How can I use an enum in an emitted assembly to define the input
parameter of a method?