Create Assemblies Dynamically by Using Builder Classes
public static void CreateStudentDynamicAssembly()
{
AppDomain myDomain = Thread.GetDomain();
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "CreatingDynamicAssembliesDemo";
AssemblyBuilder myAssemblyBuilder = myDomain.DefineDynamicAssembly(myAssemblyName,
AssemblyBuilderAccess.RunAndSave);
ModuleBuilder stuModule = CreateModule(myAssemblyBuilder, myAssemblyName);
TypeBuilder stuTypeBuilder = CreateStudentTypeBuilder(stuModule);
CreateSayHelloMethod(stuTypeBuilder);
CreateFullNameField(stuTypeBuilder);
CreateFullNameProperty(stuTypeBuilder);
myAssemblyBuilder.Save(myAssemblyName.Name + ".dll");
}//End CreateDynamicAssembly
{
AppDomain myDomain = Thread.GetDomain();
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "CreatingDynamicAssembliesDemo";
AssemblyBuilder myAssemblyBuilder = myDomain.DefineDynamicAssembly(myAssemblyName,
AssemblyBuilderAccess.RunAndSave);
ModuleBuilder stuModule = CreateModule(myAssemblyBuilder, myAssemblyName);
TypeBuilder stuTypeBuilder = CreateStudentTypeBuilder(stuModule);
CreateSayHelloMethod(stuTypeBuilder);
CreateFullNameField(stuTypeBuilder);
CreateFullNameProperty(stuTypeBuilder);
myAssemblyBuilder.Save(myAssemblyName.Name + ".dll");
}//End CreateDynamicAssembly
0 Comments:
Post a Comment
<< Home