当前位置: 首页>>代码示例>>C#>>正文


C# AppDomain.DefineDynamicAssembly方法代码示例

本文整理汇总了C#中System.AppDomain.DefineDynamicAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.DefineDynamicAssembly方法的具体用法?C# AppDomain.DefineDynamicAssembly怎么用?C# AppDomain.DefineDynamicAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.AppDomain的用法示例。


在下文中一共展示了AppDomain.DefineDynamicAssembly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClassTypeBuilder

 /// <summary>
 /// Creates a new TypeBuilder in the given domain
 /// </summary>
 /// <param name="domain">The domain.</param>
 /// <param name="assemblyNameStr">The assembly name string.</param>
 /// <param name="dynamicModuleName">Name of the dynamic module.</param>
 /// <param name="typeName">Name of the type.</param>
 /// <returns></returns>
 public static TypeBuilder GetClassTypeBuilder(AppDomain domain, string assemblyNameStr, string dynamicModuleName, string typeName)
 {
     AssemblyName assemblyName = new AssemblyName(assemblyNameStr);
     AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
     ModuleBuilder module = assemblyBuilder.DefineDynamicModule(dynamicModuleName);
     return module.DefineType(typeName, TypeAttributes.Public | TypeAttributes.Class);
 }
开发者ID:jseijas,项目名称:supido,代码行数:15,代码来源:TypeBuilderHelper.cs

示例2: AssemblyEmitter

		public AssemblyEmitter( string assemblyName, bool canSave )
		{
			m_AssemblyName = assemblyName;

			m_AppDomain = AppDomain.CurrentDomain;

			m_AssemblyBuilder = m_AppDomain.DefineDynamicAssembly(
				new AssemblyName( assemblyName ),
				canSave ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Run
			);

			if ( canSave )
			{
				m_ModuleBuilder = m_AssemblyBuilder.DefineDynamicModule(
					assemblyName,
					String.Format( "{0}.dll", assemblyName.ToLower() ),
					false
				);
			}
			else
			{
				m_ModuleBuilder = m_AssemblyBuilder.DefineDynamicModule(
					assemblyName,
					false
				);
			}
		}
开发者ID:nick12344356,项目名称:The-Basement,代码行数:27,代码来源:Emitter.cs

示例3: CreateMyAsm

        // 调用者传入一个AppDomain类型
        public static void CreateMyAsm(AppDomain curAppDomain)
        {
            // 建立通用的程序集特征
            AssemblyName assemblyName = new AssemblyName();
            assemblyName.Name = "MyAssembly";
            assemblyName.Version = new Version("1.0.0.0");

            // 在当前AppDomain(应用程序域)中创建一个新的程序集
            AssemblyBuilder assembly = 
                curAppDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);

            // 鉴于我们构造的是一个单文件程序集,模块的名字就是程序集的名字
            ModuleBuilder module = assembly.DefineDynamicModule("MyAssembly", "MyAssembly.dll");

            // 定义一个公共类“HelloWorld”
            TypeBuilder helloWorldClass = 
                module.DefineType("MyAssembly.HelloWorld", TypeAttributes.Public);

            // 定义一个私有字符串成员变量“theMessage”
            FieldBuilder msgField = 
                helloWorldClass.DefineField("theMessage", Type.GetType("System.String"), 
                FieldAttributes.Private);

            // 创建自定义的构造函数

            Type[] constructorArgs = new Type[1];
            constructorArgs[0] = typeof(string);

            ConstructorBuilder constructor = 
                helloWorldClass.DefineConstructor(MethodAttributes.Public, 
                CallingConventions.Standard, constructorArgs);

            ILGenerator constructorIL = constructor.GetILGenerator();
            constructorIL.Emit(OpCodes.Ldarg_0);
            Type objectClass = typeof(object);
            ConstructorInfo superConstructor = objectClass.GetConstructor(new Type[0]);
            constructorIL.Emit(OpCodes.Call, superConstructor);
            constructorIL.Emit(OpCodes.Ldarg_0);
            constructorIL.Emit(OpCodes.Ldarg_1);
            constructorIL.Emit(OpCodes.Stfld, msgField);
            constructorIL.Emit(OpCodes.Ret);

            helloWorldClass.DefineDefaultConstructor(MethodAttributes.Public);

            MethodBuilder getMsgMethod =
                helloWorldClass.DefineMethod("GetMsg", MethodAttributes.Public, typeof(string), null);
            ILGenerator methodIL = getMsgMethod.GetILGenerator();
            methodIL.Emit(OpCodes.Ldarg_0);
            methodIL.Emit(OpCodes.Ldfld, msgField);
            methodIL.Emit(OpCodes.Ret);

            MethodBuilder sayHiMethod = helloWorldClass.DefineMethod("SayHello", MethodAttributes.Public, null, null);
            methodIL = sayHiMethod.GetILGenerator();
            methodIL.EmitWriteLine("Hello form the HelloWorld class!");
            methodIL.Emit(OpCodes.Ret);

            helloWorldClass.CreateType();

            assembly.Save("MyAssembly.dll");
        }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:61,代码来源:Program.cs

示例4: MainWindow

 public MainWindow()
 {
     Microsoft.CodeAnalysis.CSharp.Scrip
     InitializeComponent();
     otherDomain = AppDomain.CreateDomain("Other");
     otherDomain.DefineDynamicAssembly(new AssemblyName("Fiddle.dll"), AssemblyBuilderAccess.RunAndCollect);
     otherDomain.AssemblyLoad += Executor.CurrentDomain_AssemblyLoad;
 }
开发者ID:zeldafreak,项目名称:Area51,代码行数:8,代码来源:MainWindow.xaml.cs

示例5: DefineDynamicAssembly

		public AssemblyBuilder DefineDynamicAssembly(AppDomain appDomain, AssemblyName name)
		{
#if DEBUG
			AssemblyBuilderAccess access = AssemblyBuilderAccess.RunAndSave;
#else
			AssemblyBuilderAccess access = AssemblyBuilderAccess.Run;
#endif
			return appDomain.DefineDynamicAssembly(name, access);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:9,代码来源:DefaultProxyAssemblyBuilder.cs

示例6: BeginModule

 public void BeginModule(string ifile)
 {
     appdomain	= System.Threading.Thread.GetDomain();
     appname		= getAssemblyName(filename);
     appbuild	= appdomain.DefineDynamicAssembly(appname, AssemblyBuilderAccess.Save, ".");
     emodule		= appbuild.DefineDynamicModule(filename + "_module", io.GetOutputFilename(), io.getGenDebug());
     Guid g 		= System.Guid.Empty;
     if (io.getGenDebug()) srcdoc = emodule.DefineDocument(ifile, g, g, g);
 }
开发者ID:master,项目名称:plil,代码行数:9,代码来源:exe.cs

示例7: EmitTranslator

        public EmitTranslator(AppDomain hostDomain, string name)
        {
            AssemblyName asmName = new AssemblyName(name);
            m_assembly = hostDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);

            m_module = m_assembly.DefineDynamicModule(name + ".exe", true);
            m_typeTable = new ExtensionTable<Type>();
            m_methodTable = new ExtensionTable<MethodInfo>();
            m_ctorTable = new ExtensionTable<ConstructorInfo>();
            m_fieldTable = new ExtensionTable<FieldInfo>();
        }
开发者ID:destinyclown,项目名称:VBF,代码行数:11,代码来源:EmitTranslator.cs

示例8: DotNetCompiler

        public DotNetCompiler(LibraryContext context, string filename)
        {
            Context = context;
            var fi = new FileInfo(filename);
            Path = fi;

            BuilderAppDomain = AppDomain.CurrentDomain;
            AssemblyBuilder = BuilderAppDomain.DefineDynamicAssembly(new AssemblyName(fi.Name), AssemblyBuilderAccess.RunAndSave, fi.DirectoryName);
            MainModule = AssemblyBuilder.DefineDynamicModule(fi.Name, fi.Name);
            ScriptsType = MainModule.DefineType("Scripts", TypeAttributes.Class);
            RoomsType = MainModule.DefineType("Rooms", TypeAttributes.Class);
        }
开发者ID:MilesBoulanger,项目名称:game-creator,代码行数:12,代码来源:DotNetCompiler.cs

示例9: CreateMyAsm

        static void CreateMyAsm(AppDomain currAppDomain) {
            AssemblyName assemblyName = new AssemblyName();
            assemblyName.Name = "MyAssembly";
            assemblyName.Version = new Version("1.0.0.0");

            AssemblyBuilder assembly = currAppDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);

            ModuleBuilder module = assembly.DefineDynamicModule("MyAssembly", "MyAssembly.dll");

            TypeBuilder helloWorldClass = module.DefineType("MyAssembly.HelloWorld", TypeAttributes.Public);

            FieldBuilder msgField = helloWorldClass.DefineField("theMessage", typeof(string), FieldAttributes.Private);

            Type[] constructorArgs = new Type[1];
            constructorArgs[0] = typeof(string);

            ConstructorBuilder constructor = helloWorldClass.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, constructorArgs);
            ILGenerator constructorIL = constructor.GetILGenerator();
            constructorIL.Emit(OpCodes.Ldarg_0);
            Type objectClass = typeof(object);

            ConstructorInfo superConstructor = objectClass.GetConstructor(new Type[0]);
            constructorIL.Emit(OpCodes.Call, superConstructor);
            constructorIL.Emit(OpCodes.Ldarg_0);
            constructorIL.Emit(OpCodes.Ldarg_1);
            constructorIL.Emit(OpCodes.Stfld, msgField);
            constructorIL.Emit(OpCodes.Ret);

            helloWorldClass.DefineDefaultConstructor(MethodAttributes.Public);

            MethodBuilder getMsgMethod = helloWorldClass.DefineMethod("GetMsg", MethodAttributes.Public, typeof(string), null);
            ILGenerator methodIL = getMsgMethod.GetILGenerator();
            methodIL.Emit(OpCodes.Ldarg_0);
            methodIL.Emit(OpCodes.Ldfld, msgField);
            methodIL.Emit(OpCodes.Ret);

            MethodBuilder sayHiMethod = helloWorldClass.DefineMethod("SayHello", MethodAttributes.Public, null, null);
            methodIL = sayHiMethod.GetILGenerator();
            methodIL.EmitWriteLine("Hello from the HelloWorld class");
            methodIL.Emit(OpCodes.Ret);

            helloWorldClass.CreateType();

            assembly.Save("MyAssembly.dll");




        }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:49,代码来源:Program.cs

示例10: ClassDeserializer

        public ClassDeserializer(ClassManager parent)
        {
            m_parent = parent;

            var an = new AssemblyName()
            {
                Name = "HelloReflectionEmit"
            };

            m_ad = AppDomain.CurrentDomain;
            m_ab = m_ad.DefineDynamicAssembly(an, System.Reflection.Emit.AssemblyBuilderAccess.RunAndSave);
            m_mb = m_ab.DefineDynamicModule(an.Name, "Hello.exe");

            m_stack = new Stack<ClassFrame>();
        }
开发者ID:CurlyBrackets,项目名称:DynamicLibrary,代码行数:15,代码来源:ClassDeserializer.cs

示例11: BeginModule

 public void BeginModule(string fileName)
 {
     FileInfo f = new FileInfo(fileName);
     appDomain = Thread.GetDomain();
     asmName = new AssemblyName();
     asmName.Name = f.Name;
     asmBuilder = appDomain.DefineDynamicAssembly(
         asmName,
         AssemblyBuilderAccess.RunAndSave,
         f.DirectoryName
         );
     modBuilder = asmBuilder.DefineDynamicModule(
         asmName.Name,
         asmName.Name);
 }
开发者ID:olympum,项目名称:caffeine,代码行数:15,代码来源:PEemitter.cs

示例12: Create

        public static void Create( AppDomain domain, string asmName, string progName )
        {
            AssemblyName assemblyName = new AssemblyName();
             assemblyName.Name = asmName;
             assemblyName.Version = new Version("1.0.0.0");

             AssemblyBuilder assembler = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
             ModuleBuilder moduleBuilder = assembler.DefineDynamicModule( asmName, asmName + ".dll" );
             TypeBuilder helloWorldBuilder = moduleBuilder.DefineType(asmName + "." + progName, TypeAttributes.Public);
             FieldBuilder fieldBuilder = helloWorldBuilder.DefineField("theMessage", Type.GetType("System.String"), FieldAttributes.Private);

             Type[] constructorArgs = new Type[1];
             constructorArgs[0] = typeof (string);
             ConstructorBuilder constructor = helloWorldBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, constructorArgs);
             ILGenerator constructorIl = constructor.GetILGenerator();
             constructorIl.Emit(OpCodes.Ldarg_0);
             Type objectClass = typeof(object);
             ConstructorInfo superConstructor = objectClass.GetConstructor(new Type[0]);
             constructorIl.Emit(OpCodes.Call, superConstructor);
             constructorIl.Emit( OpCodes.Ldarg_0 );
             constructorIl.Emit( OpCodes.Ldarg_1 );
             constructorIl.Emit( OpCodes.Stfld, fieldBuilder );
             constructorIl.Emit( OpCodes.Ret );

             helloWorldBuilder.DefineDefaultConstructor(MethodAttributes.Public);
             MethodBuilder methodBuilder = helloWorldBuilder.DefineMethod("GetMsg", MethodAttributes.Public, typeof (string), null);
             ILGenerator methodIl = methodBuilder.GetILGenerator();
             methodIl.Emit( OpCodes.Ldarg_0 );
             methodIl.Emit( OpCodes.Ldfld, fieldBuilder );
             methodIl.Emit( OpCodes.Ret );

             MethodBuilder executor = helloWorldBuilder.DefineMethod("SayHello", MethodAttributes.Public, null, null);
             methodIl = executor.GetILGenerator();
             methodIl.EmitWriteLine("Hello from the HelloWorld class!");
             methodIl.Emit(OpCodes.Ret);

             helloWorldBuilder.CreateType();
             assembler.Save( asmName + ".dll" );
        }
开发者ID:ghostmonk,项目名称:CSharpTutorials,代码行数:39,代码来源:AssemblyMaker.cs

示例13: DefineDynamicAssembly

		public AssemblyBuilder DefineDynamicAssembly(AppDomain appDomain, AssemblyName name)
		{
			return assembly ?? (assembly = appDomain.DefineDynamicAssembly(new AssemblyName(assemblyName), AssemblyBuilderAccess.RunAndSave));
		}
开发者ID:uQr,项目名称:NHibernate.ProxyGenerators,代码行数:4,代码来源:SavingProxyAssemblyBuilder.cs

示例14: DefineDynamicAssembly

	static void DefineDynamicAssembly (AppDomain domain)
	{
		AssemblyName assemblyName = new AssemblyName ();
		assemblyName.Name = "MyDynamicAssembly";

		AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly (assemblyName, AssemblyBuilderAccess.Run);
		ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule ("MyDynamicModule");
		TypeBuilder typeBuilder = moduleBuilder.DefineType ("MyDynamicType", TypeAttributes.Public);
		ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, null);
		ILGenerator ilGenerator = constructorBuilder.GetILGenerator ();
		ilGenerator.EmitWriteLine ("MyDynamicType instantiated!");
		ilGenerator.Emit (OpCodes.Ret);
		typeBuilder.CreateType ();
	}
开发者ID:Profit0004,项目名称:mono,代码行数:14,代码来源:AssemblyBuilderTest.cs

示例15: BuildAssembly

        private void BuildAssembly(AppDomain appDomain, string dir, string filename)
        {
            // Prepare the assembly-level permissions.
            PermissionSet requiredPermissions = new PermissionSet(null);
            PermissionSet optionalPermissions = new PermissionSet(null);
            PermissionSet refusedPermissions = new PermissionSet(null);

            foreach (SecurityDeclaration securityDeclaration in assemblyDefinition.SecurityDeclarations)
            {
                switch (securityDeclaration.Action)
                {
                    case Mono.Cecil.SecurityAction.RequestMinimum:
                        requiredPermissions = requiredPermissions.Union(securityDeclaration.PermissionSet);
                        break;
                    case Mono.Cecil.SecurityAction.RequestOptional:
                        optionalPermissions = optionalPermissions.Union(securityDeclaration.PermissionSet);
                        break;
                    case Mono.Cecil.SecurityAction.RequestRefuse:
                        refusedPermissions = refusedPermissions.Union(securityDeclaration.PermissionSet);
                        break;
                }
            }

            // Build the dynamic assembly.
            AssemblyBuilder assemblyBuilder = appDomain.DefineDynamicAssembly(
                new AssemblyName(assemblyDefinition.Name.FullName),
                AssemblyBuilderAccess.RunAndSave, dir,
                requiredPermissions, optionalPermissions, refusedPermissions);
            dynamicAssembly = new DynamicAssembly(assemblyBuilder, filename);

            // TODO: Set entry point and assembly kind.

            foreach (ModuleDefinition moduleDefinition in assemblyDefinition.Modules)
                BuildModule(moduleDefinition);

            metadataPass.Add(delegate
            {
                InitializeCustomAttributes(assemblyBuilder.SetCustomAttribute, assemblyDefinition.CustomAttributes);
            });
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:40,代码来源:DynamicAssemblyBuilder.cs


注:本文中的System.AppDomain.DefineDynamicAssembly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。