12 Mart 2018 Pazartesi

AssemblyBuilder Sınıfı

Constructor
Şöyle yaparız.
// Get the current application domain for the current thread
AppDomain currentDomain = AppDomain.CurrentDomain;

// Create a dynamic assembly in the current application domain,
// and allow it to be executed and saved to disk.
AssemblyName name = new AssemblyName("MyEnums");
AssemblyBuilder assemblyBuilder = currentDomain.DefineDynamicAssembly(name,
                                      AssemblyBuilderAccess.RunAndSave);
DefineDynamicModule metodu
ModuleBuilder nesnesi yaratır.
Örnek
Şöyle yaparız.
AssemblyName name = new AssemblyName("MyEnums");

// Define a dynamic module in "MyEnums" assembly.
// For a single-module assembly, the module has the same name as the assembly.
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(name.Name,
                                  name.Name + ".dll");
Örnek
Şöyle yaparız.
var assmName = new AssemblyName("DynamicAssemblyExample");
var moduleBuilder = assmemblyBuilder.DefineDynamicModule(assmName.Name,
  assmName.Name + ".dll");
DefineType metodu
Şöyle yaparız.
TypeBuilder t = moduleBuilder.DefineType("MyProgram", TypeAttributes.Public));
GetType metodu
Şöyle yaparız.
Type t = mb.GetType("MyProgram"), 
Save metodu
Şöyle yaparız.
// Create a dynamic assembly in the current application domain,
// and allow it to be executed and saved to disk.
AssemblyName name = new AssemblyName("MyEnums");

// Finally, save the assembly
assemblyBuilder.Save(name.Name + ".dll");

Hiç yorum yok:

Yorum Gönder