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


C# Emit.AssemblyBuilder类代码示例

本文整理汇总了C#中System.Reflection.Emit.AssemblyBuilder的典型用法代码示例。如果您正苦于以下问题:C# AssemblyBuilder类的具体用法?C# AssemblyBuilder怎么用?C# AssemblyBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Reset

 public void Reset()
 {
     UniqueCounter++;
     var CurrentAppDomain = AppDomain.CurrentDomain;
     AssemblyBuilder = CurrentAppDomain.DefineDynamicAssembly(new AssemblyName("assembly" + UniqueCounter), AssemblyBuilderAccess.RunAndSave);
     ModuleBuilder = AssemblyBuilder.DefineDynamicModule("module" + UniqueCounter);
 }
开发者ID:mrcmunir,项目名称:cspspemu,代码行数:7,代码来源:MipsEmiter.cs

示例2: PropertyAccessor

 static PropertyAccessor()
 {
     AssemblyName asmName = new AssemblyName();
     asmName.Name = "$Assembly.Hprose.IO.PropertyAccessor";
     asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
     modBuilder = asmBuilder.DefineDynamicModule("$Module.PropertyAccessor");
 }
开发者ID:JesonRen,项目名称:hprose,代码行数:7,代码来源:PropertyAccessor.cs

示例3: SetAccessorFactory

         /// <summary>
        /// Initializes a new instance of the <see cref="SetAccessorFactory"/> class.
        /// </summary>
        /// <param name="allowCodeGeneration">if set to <c>true</c> [allow code generation].</param>
        public SetAccessorFactory(bool allowCodeGeneration)
		{
            if (allowCodeGeneration)
            {
                // Detect runtime environment and create the appropriate factory
                if (Environment.Version.Major >= 2)
                {
                    _createPropertySetAccessor = new CreatePropertySetAccessor(CreateDynamicPropertySetAccessor);
                    _createFieldSetAccessor = new CreateFieldSetAccessor(CreateDynamicFieldSetAccessor);
                }
                else
                {
                    AssemblyName assemblyName = new AssemblyName();
                    assemblyName.Name = "iBATIS.FastSetAccessor" + HashCodeProvider.GetIdentityHashCode(this);

                    // Create a new assembly with one module
                    _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
                    _moduleBuilder = _assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll");

                    _createPropertySetAccessor = new CreatePropertySetAccessor(CreatePropertyAccessor);
                    _createFieldSetAccessor = new CreateFieldSetAccessor(CreateFieldAccessor);
                }
            }
            else
            {
                _createPropertySetAccessor = new CreatePropertySetAccessor(CreateReflectionPropertySetAccessor);
                _createFieldSetAccessor = new CreateFieldSetAccessor(CreateReflectionFieldSetAccessor);
            }
        }
开发者ID:techvenky,项目名称:mybatisnet,代码行数:33,代码来源:SetAccessorFactory.cs

示例4: NativeCall

        static NativeCall() {

            // The static constructor is responsible for generating the
            // assembly and the methods that implement the IJW thunks.
            //
            // To do this, we actually use reflection on the INativeCall
            // interface (defined below) and generate the required thunk 
            // code based on the method signatures.

            AssemblyName aname = new AssemblyName();
            aname.Name = "e__NativeCall_Assembly";
            AssemblyBuilderAccess aa = AssemblyBuilderAccess.Run;

            aBuilder = Thread.GetDomain().DefineDynamicAssembly(aname, aa);
            mBuilder = aBuilder.DefineDynamicModule("e__NativeCall_Module");

            TypeAttributes ta = TypeAttributes.Public;
            TypeBuilder tBuilder = mBuilder.DefineType("e__NativeCall", ta);

            Type iType = typeof(INativeCall);
            tBuilder.AddInterfaceImplementation(iType);

            // Use reflection to loop over the INativeCall interface methods, 
            // calling GenerateThunk to create a managed thunk for each one.

            foreach (MethodInfo method in iType.GetMethods()) {
                GenerateThunk(tBuilder, method);
            }
            
            Type theType = tBuilder.CreateType();

            Impl = (INativeCall)Activator.CreateInstance(theType);

        }
开发者ID:JackHang,项目名称:Wox,代码行数:34,代码来源:nativecall.cs

示例5: CreateCallee

 private void CreateCallee()
 {
     AssemblyName myAssemblyName = new AssemblyName();
     myAssemblyName.Name = "EnumAssembly";
     _myAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run);
     _myModuleBuilder = TestLibrary.Utilities.GetModuleBuilder(_myAssemblyBuilder, "EnumModule.mod");
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:EnumBuilderBaseType.cs

示例6: DynamicAssemblyManager

        static DynamicAssemblyManager()
        {
#if !SILVERLIGHT
            assemblyName = new AssemblyName("NLiteDynamicAssembly");
            assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
                assemblyName,
                AssemblyBuilderAccess.RunAndSave
                );

            moduleBuilder = assemblyBuilder.DefineDynamicModule(
                assemblyName.Name,
                assemblyName.Name + ".dll",
                true);

            Module = assemblyBuilder.GetModules().FirstOrDefault();
           
#else
            assemblyName = new AssemblyName("EmitMapperAssembly.SL");
            assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
                  assemblyName,
                  AssemblyBuilderAccess.Run
                  );
            moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name, true);
#endif
        }
开发者ID:netcasewqs,项目名称:nlite,代码行数:25,代码来源:DynamicAssemblyManager.cs

示例7: GetInvokeMethod

        public MethodInfo GetInvokeMethod(string methodName, Type returnType, Type[] types)
        {
            string entryName = methodName;
            if (assemblyBuilder == null)
            {
                AssemblyName assemblyName = new AssemblyName(AssemblyName);
                assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
                moduleBuilder = assemblyBuilder.DefineDynamicModule(AssemblyName);
            }

            var defineType = moduleBuilder.DefineType(GetDefineTypeName(methodName));
            var methodBuilder = defineType.DefinePInvokeMethod(methodName, dllName, entryName,
                       MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,
                       CallingConventions.Standard,
                       returnType, types,
                       CallingConvention, CharSet);
            if ((returnType != null) && (returnType != typeof(void)))
            {
                methodBuilder.SetImplementationFlags(MethodImplAttributes.PreserveSig | methodBuilder.GetMethodImplementationFlags());
            }
            var type = defineType.CreateType();

            var method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
            return method;
        }
开发者ID:SchwarzerLoewe,项目名称:Ecmd,代码行数:25,代码来源:DLLImporter.cs

示例8: Emitter

 public Emitter(EmitterOptions options)
 {
     _options = options;
     _assemblyName = new AssemblyName(_options.AssemblyName);
     _assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave);// TODO: temp for debugging .RunAndCollect);
     if (_options.DebugOn)
         _assembly.SetCustomAttribute
         (
             new CustomAttributeBuilder
             (
                 typeof(DebuggableAttribute).GetConstructor
                 (
                     new System.Type[] { typeof(DebuggableAttribute.DebuggingModes) }
                 ),
                 new object[]
                 {
                     DebuggableAttribute.DebuggingModes.DisableOptimizations |
                     DebuggableAttribute.DebuggingModes.Default
                 }
             )
         );
     _module = _assembly.DefineDynamicModule(_assemblyName.Name, _assemblyName.Name + ".dll", _options.DebugOn);
     if (_options.DebugOn)
         _symbolWriter = _module.DefineDocument(_options.SourceFileName, Guid.Empty, Guid.Empty, Guid.Empty);
     _tupleToNative = new Dictionary<Type.TupleType, System.Type>();
 }
开发者ID:jgabb8989,项目名称:DotQL,代码行数:26,代码来源:Emitter.cs

示例9: ILDynamicTypeImpl

 public ILDynamicTypeImpl(string name, Type baseType, Type[] interfaces)
 {
     _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(name), AssemblyBuilderAccess.RunAndCollect);
     _moduleBuilder = _assemblyBuilder.DefineDynamicModule(name + ".dll", true);
     _typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, baseType, interfaces);
     _forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
 }
开发者ID:Bobris,项目名称:BTDB,代码行数:7,代码来源:ILDynamicTypeImpl.cs

示例10: EmitPropertyGetAccessor

        /// <summary>
        /// Initializes a new instance of the <see cref="EmitPropertyGetAccessor"/> class.
        /// </summary>
        /// <param name="targetObjectType">Type of the target object.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="assemblyBuilder">The <see cref="AssemblyBuilder"/>.</param>
        /// <param name="moduleBuilder">The <see cref="ModuleBuilder"/>.</param>
        public EmitPropertyGetAccessor(Type targetObjectType, string propertyName, AssemblyBuilder assemblyBuilder, ModuleBuilder moduleBuilder)
        {
            _targetType = targetObjectType;
            _propertyName = propertyName;

            // deals with Overriding a property using new and reflection
            // http://blogs.msdn.com/thottams/archive/2006/03/17/553376.aspx
            PropertyInfo propertyInfo = _targetType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            if (propertyInfo == null)
            {
                propertyInfo = _targetType.GetProperty(propertyName);
            }

            // Make sure the property exists
            if(propertyInfo == null)
            {
                throw new NotSupportedException(
                    string.Format("Property \"{0}\" does not exist for type "
                    + "{1}.", propertyName, _targetType));
            }
            else
            {
                this._propertyType = propertyInfo.PropertyType;
                _canRead = propertyInfo.CanRead;
                this.EmitIL(assemblyBuilder, moduleBuilder);
            }
        }
开发者ID:hejiquan,项目名称:iBATIS_2010,代码行数:34,代码来源:EmitPropertyGetAccessor.cs

示例11: RunTimeCreator

        /// <summary>
        /// Initializes the runtime compiler and metadata references for dynamic assembly.
        /// </summary>
        public RunTimeCreator()
        {
            usedNameDict = new Dictionary<string, int>();
            // Set references to runtime compiling
            isCompiled = new List<string>();
            var t = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            metadataRef = new List<MetadataReference>();
            metadataRef.Add(MetadataFileReference.CreateAssemblyReference("mscorlib"));
            metadataRef.Add(new MetadataFileReference(typeof(Strategy.MyMogre).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(Strategy.Game).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(GameObjectControl.Game_Objects.StaticGameObjectBox.StaticGameObject).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(Team).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(System.Linq.Enumerable).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(LinkedList<>).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(Path.GetFullPath((new Uri(t + "\\\\Mogre.dll")).LocalPath)));
            metadataRef.Add(new MetadataFileReference(typeof(PropertyManager).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(GameObjectControl.Game_Objects.StaticGameObjectBox.IStaticGameObject).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(ActionAnswer).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(PropertyEnum).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(XmlLoadException).Assembly.Location));
            metadataRef.Add(new MetadataFileReference(typeof(ConstructorFieldAttribute).Assembly.Location));

            comilationOption = new CompilationOptions(OutputKind.DynamicallyLinkedLibrary);

            assemblyBuilder =
                AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("DynamicAssembly" + Guid.NewGuid()),
                                                              AssemblyBuilderAccess.RunAndCollect);
            moduleBuilder = assemblyBuilder.DefineDynamicModule("DynamicModule");
        }
开发者ID:vavrekmichal,项目名称:StrategyGame,代码行数:32,代码来源:RunTimeCreator.cs

示例12: RegexTypeCompiler

 internal RegexTypeCompiler(AssemblyName an, CustomAttributeBuilder[] attribs, string resourceFile)
 {
     new ReflectionPermission(PermissionState.Unrestricted).Assert();
     try
     {
         List<CustomAttributeBuilder> assemblyAttributes = new List<CustomAttributeBuilder>();
         CustomAttributeBuilder item = new CustomAttributeBuilder(typeof(SecurityTransparentAttribute).GetConstructor(Type.EmptyTypes), new object[0]);
         assemblyAttributes.Add(item);
         CustomAttributeBuilder builder2 = new CustomAttributeBuilder(typeof(SecurityRulesAttribute).GetConstructor(new Type[] { typeof(SecurityRuleSet) }), new object[] { SecurityRuleSet.Level2 });
         assemblyAttributes.Add(builder2);
         this._assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave, assemblyAttributes);
         this._module = this._assembly.DefineDynamicModule(an.Name + ".dll");
         if (attribs != null)
         {
             for (int i = 0; i < attribs.Length; i++)
             {
                 this._assembly.SetCustomAttribute(attribs[i]);
             }
         }
         if (resourceFile != null)
         {
             this._assembly.DefineUnmanagedResource(resourceFile);
         }
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:RegexTypeCompiler.cs

示例13: CreateAssembly

 private void CreateAssembly()
 {  //to create an assembly programmatically
     AssemblyName Name = new AssemblyName("NaiveORM0Classes");
     AppDomain Domain = Thread.GetDomain();
     _Builder = Domain.DefineDynamicAssembly(Name, AssemblyBuilderAccess.Run);
     _Module = _Builder.DefineDynamicModule("NaiveORM0ClassesM");
 }
开发者ID:fabm22,项目名称:NaiveORM,代码行数:7,代码来源:ClassManager.cs

示例14: DynamicAssembly

        public DynamicAssembly()
        {
            int assemblyNumber = Interlocked.Increment(ref _assemblyCount);
            _assemblyName = new AssemblyName {
                Name = String.Format("Quokka.DynamicAssembly.N{0}", assemblyNumber)
            };
            string moduleName = AssemblyName.Name;
            _dynamicClassNamespace = AssemblyName.Name;

            if (CreateFiles)
            {
                _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(
                    AssemblyName, AssemblyBuilderAccess.RunAndSave);

                // Add a debuggable attribute to the assembly saying to disable optimizations
                // See http://blogs.msdn.com/rmbyers/archive/2005/06/26/432922.aspx
                Type daType = typeof (DebuggableAttribute);
                ConstructorInfo daCtor = daType.GetConstructor(new[] {typeof (bool), typeof (bool)});
                var daBuilder = new CustomAttributeBuilder(daCtor, new object[] {true, true});
                _assemblyBuilder.SetCustomAttribute(daBuilder);

                _moduleBuilder = _assemblyBuilder.DefineDynamicModule(moduleName);
                _canSave = true;
            }
            else
            {
                _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run);
                _moduleBuilder = _assemblyBuilder.DefineDynamicModule(moduleName);
            }
        }
开发者ID:jjeffery,项目名称:Cesto,代码行数:30,代码来源:DynamicAssembly.cs

示例15: WrapFactory

 /// <summary>
 /// A static constructor.
 /// </summary>
 static WrapFactory()
 {
     AssemblyName asmName = new AssemblyName();
     asmName.Name = "SqlWrapperDynamicAsm";
     m_asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);
     m_modBuilder = m_asmBuilder.DefineDynamicModule("SqlWrapperDynamicModule");
 }
开发者ID:divyang4481,项目名称:appleseedapp,代码行数:10,代码来源:WrapFactory.cs


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