Apologies if I'm missing something obvious, but when I create a new type with Reflection.Emit, how do I specify what namespace it should be in?
ie..
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "TestDynamic";
AssemblyBuilder assemblyBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(
assemblyName,
AssemblyBuilderAccess.Save);
ModuleBuilder moduleBuilder =
AssemblyBuilder.DefineDynamicModule("TestDynamic", "TestDynamic.dll");
TypeBuilder myTestInterface =
moduleBuilder.DefineType("MyTestInterface",
TypeAttributes.Public | TypeAttributes.Interface, typeof(object));
How do I give a namespace for myTestInterface
?
Emit is a powerful namespace in which we can dynamically emit transient and persisting assemblies at runtime. Reflection. Emit produces a low-level, language-neutral MSIL. Normally, we create an assembly by saving its source code to disk and then compiling that source code.
Reflection. Emit namespace that allow a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) at run time and optionally generate a portable executable (PE) file on disk. Script engines and compilers are the primary users of this namespace.
A dynamic assembly is an assembly that is created using the Reflection Emit APIs. You can use AssemblyBuilder to generate dynamic assemblies in memory and execute their code during the same application run.
Define it where you define the type:
moduleBuilder.DefineType("MyNamespace.MyTestInterface",
TypeAttributes.Public | TypeAttributes.Interface,
typeof(object));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With