• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Emit.ModuleBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ModuleBuilderData

 internal ModuleBuilderData(ModuleBuilder module, string strModuleName, string strFileName, int tkFile)
 {
     this.m_globalTypeBuilder = new TypeBuilder(module);
     this.m_module = module;
     this.m_tkFile = tkFile;
     this.InitNames(strModuleName, strFileName);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:ModuleBuilderData.cs


示例2: RuntimeTypeProvider

 static RuntimeTypeProvider()
 {
     ModuleBuilder = Thread
         .GetDomain()
         .DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run)
         .DefineDynamicModule(AssemblyName.Name);
 }
开发者ID:calebjenkins,项目名称:Highway.Data,代码行数:7,代码来源:RuntimeTypeProvider.cs


示例3: GetTypeBuilder

 private TypeBuilder GetTypeBuilder(Type sourceType, ModuleBuilder moduleBuilder)
 {
     return moduleBuilder.DefineType(
             SnapshotNameGenerator.Generate(sourceType),
             TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.Sealed,
             SnapshotBaseType);
 }
开发者ID:VincentSchippefilt,项目名称:ncqrs,代码行数:7,代码来源:DynamicSnapshotTypeBuilder.cs


示例4: Scope

 public Scope(ModuleBuilder moduleBuilder)
 {
     _vars = new Dictionary<string, ParameterExpression>();
     _types = new Dictionary<string, Type>();
     _func = new Dictionary<string, LambdaExpression>();
     _moduleBuilder = moduleBuilder;
 }
开发者ID:dayanruben,项目名称:TigerConverters,代码行数:7,代码来源:Scope.cs


示例5: EmitOwnerMappingType

        private TypeBuilder EmitOwnerMappingType(IPropertyMappingProvider map, ModuleBuilder defineDynamicModule, string ownerTypeName)
        {
            var owner = defineDynamicModule.DefineType(
                    ownerTypeName,
                    TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract,
                    null,
                    new[] { typeof(IRdfListOwner) }).CreateType();
            var ownerMapType = typeof(ListOwnerMap<>).MakeGenericType(new[] { owner });

            var mapBuilderHelper = defineDynamicModule.DefineType(ownerTypeName + "Map", TypeAttributes.Public, ownerMapType);
            var propertyBuilder = mapBuilderHelper.DefineProperty("ListPredicate", PropertyAttributes.None, typeof(Uri), null);
            var getMethod = mapBuilderHelper.DefineMethod(
                "get_ListPredicate",
                MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                typeof(Uri),
                Type.EmptyTypes);
            propertyBuilder.SetGetMethod(getMethod);

            var ilGenerator = getMethod.GetILGenerator();
            ilGenerator.Emit(OpCodes.Nop);
            ilGenerator.Emit(OpCodes.Ldstr, map.GetTerm(_ontologyProvider).ToString());
            ilGenerator.Emit(OpCodes.Newobj, typeof(Uri).GetConstructor(new[] { typeof(string) }));
            ilGenerator.Emit(OpCodes.Ret);

            return mapBuilderHelper;
        }
开发者ID:rafalrosochacki,项目名称:RomanticWeb,代码行数:26,代码来源:GeneratedListMappingSource.cs


示例6: GenerateCode

        public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
        {
            LeftOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
            RightOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);

            Label endLabel = codeGenerator.DefineLabel();
            Label trueLabel = codeGenerator.DefineLabel();

            if (LeftOperand.ReturnType == StringType.StringInstance)
            {
                codeGenerator.Emit(OpCodes.Call, typeof(String).GetMethod("CompareTo", new Type[] { typeof(string) }));
                codeGenerator.Emit(OpCodes.Ldc_I4_0);
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);
            }
            else
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);

            codeGenerator.Emit(OpCodes.Ldc_I4_0);
            codeGenerator.Emit(OpCodes.Br, endLabel);

            codeGenerator.MarkLabel(trueLabel);
            codeGenerator.Emit(OpCodes.Ldc_I4_1);

            codeGenerator.MarkLabel(endLabel);
        }
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:25,代码来源:NotEqNode.cs


示例7: SerializerEmitter

		/// <summary>
		///		Initializes a new instance of the <see cref="SerializerEmitter"/> class for enum.
		/// </summary>
		/// <param name="context">A <see cref="SerializationContext"/>.</param>
		/// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
		public SerializerEmitter( SerializationContext context, ModuleBuilder host, SerializerSpecification specification, bool isDebuggable )
			: this( host, specification, typeof( EnumMessagePackSerializer<> ).MakeGenericType( specification.TargetType ), isDebuggable )
		{
			Tracer.Emit.TraceEvent( Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName );

			this._defaultEnumSerializationMethod = context.EnumSerializationOptions.SerializationMethod;
		}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:14,代码来源:SerializerEmitter.enum.cs


示例8: Compile

 public Type Compile(IMetadataSchema schema, ModuleBuilder module, string @namespace, string typeName)
 {
     if (schema == null)
     {
         throw new ArgumentNullException(nameof(schema));
     }
     if (schema.Definitions == null)
     {
         throw new ArgumentException("There is no definition is schema.", nameof(schema));
     }
     if (module == null)
     {
         throw new ArgumentNullException(nameof(module));
     }
     if (@namespace == null)
     {
         throw new ArgumentNullException(nameof(@namespace));
     }
     if (string.IsNullOrWhiteSpace(@namespace))
     {
         throw new ArgumentException("namespace cannot be white space.", nameof(@namespace));
     }
     if (typeName == null)
     {
         throw new ArgumentNullException(nameof(typeName));
     }
     if (string.IsNullOrWhiteSpace(typeName))
     {
         throw new ArgumentException("typeName cannot be white space.", nameof(typeName));
     }
     ValidateProperties();
     return CompileCore(schema, module, @namespace, typeName);
 }
开发者ID:ansyral,项目名称:docfx,代码行数:33,代码来源:MetadataCompiler.cs


示例9: NavigatorProxyBuilder

		public NavigatorProxyBuilder(ModuleBuilder moduleBuilder, string className, Type interfaceType, Type innerType)
			: base(moduleBuilder, className, interfaceType, innerType)
		{
			_navigateValues = new List<string>();

			_innerNavigateMethod = FindInnerNavigateMethod(innerType);
			if (_innerNavigateMethod == null)
			{
				AddErrorMessage("Cannot find method with signature 'void Navigate(string)' in type {0}", innerType);
			}

			_innerCanNavigateMethod = FindInnerCanNavigateMethod(innerType);
			if (_innerCanNavigateMethod == null)
			{
				AddErrorMessage("Cannot find method with signature 'bool CanNavigate(string)' in type {0}", innerType);
			}

			_outerNavigateEnumMethod = FindOuterNavigateEnumMethod(interfaceType);
			if (_outerNavigateEnumMethod != null)
			{
				_navigateValueEnumType = _outerNavigateEnumMethod.GetParameters()[0].ParameterType;
				_outerCanNavigateEnumMethod = FindOuterCanNavigateEnumMethod(interfaceType, _navigateValueEnumType);
				_navigateValues.AddRange(Enum.GetNames(_navigateValueEnumType));
			}

			FindEvents();
			_outerNavigateMethods = FindOuterNavigateMethods();
			_outerCanNavigateProperties = FindOuterCanNavigateProperties();
		}
开发者ID:matthewc-mps-aust,项目名称:quokka,代码行数:29,代码来源:NavigatorProxyBuilder.cs


示例10: 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


示例11: 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


示例12: AbstractProxyBuilder

		public AbstractProxyBuilder(ModuleBuilder moduleBuilder, string className, Type interfaceType, Type innerType)
		{
			Verify.ArgumentNotNull(moduleBuilder, "moduleBuilder");
			Verify.ArgumentNotNull(className, "className");
			Verify.ArgumentNotNull(interfaceType, "interfaceType");
			Verify.ArgumentNotNull(innerType, "innerType");

			if (!interfaceType.IsInterface) {
				throw new ArgumentException("must be an interface type", "interfaceType");
			}

			_errorMessages = new List<string>();
			_moduleBuilder = moduleBuilder;
			_className = className;
			_interfaceType = interfaceType;
			_innerType = innerType;

			_typeBuilder = _moduleBuilder.DefineType(
				_className,
				TypeAttributes.Public |
				TypeAttributes.Class |
				TypeAttributes.AutoClass |
				TypeAttributes.AnsiClass |
				TypeAttributes.BeforeFieldInit |
				TypeAttributes.AutoLayout,
				typeof(object),
				new Type[] {_interfaceType});

			_innerFieldBuilder = _typeBuilder.DefineField("inner", _innerType, FieldAttributes.Private);
		}
开发者ID:matthewc-mps-aust,项目名称:quokka,代码行数:30,代码来源:AbstractProxyBuilder.cs


示例13: Create

        public static RowViewModelBase Create(ModuleBuilder mb, SpreadsheetViewModel viewModel, int rowNumber, int columns)
        {
            if (RowType == null)
                RowType = CreateType(mb, columns);

            return (RowViewModelBase)Activator.CreateInstance(RowType, viewModel, rowNumber);
        }
开发者ID:jflam,项目名称:spreadsheet,代码行数:7,代码来源:ViewModel.cs


示例14: CreateTypeFromInterface

        static Type CreateTypeFromInterface(ModuleBuilder builder, Type typeToProxy)
        {
            string typeName = typeToProxy.Namespace + ProxyNamespaceSuffix + "." + typeToProxy.Name;

            TypeBuilder typeBuilder = builder.DefineType(typeName, TypeAttributes.Serializable | TypeAttributes.Class |
                                                                   TypeAttributes.Public | TypeAttributes.Sealed,
                                                         typeof(object), new[] {typeToProxy});

            typeBuilder.DefineDefaultConstructor(MethodAttributes.Public);

            typeToProxy.GetAllProperties().Each(x =>
                {
                    FieldBuilder fieldBuilder = typeBuilder.DefineField("field_" + x.Name, x.PropertyType, FieldAttributes.Private);

                    PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(x.Name, x.Attributes | PropertyAttributes.HasDefault,
                                                                                 x.PropertyType, null);

                    MethodBuilder getMethod = GetGetMethodBuilder(x, typeBuilder, fieldBuilder);
                    MethodBuilder setMethod = GetSetMethodBuilder(x, typeBuilder, fieldBuilder);

                    propertyBuilder.SetGetMethod(getMethod);
                    propertyBuilder.SetSetMethod(setMethod);
                });

            return typeBuilder.CreateType();
        }
开发者ID:hakeemsm,项目名称:Magnum,代码行数:26,代码来源:InterfaceImplementationBuilder.cs


示例15: PropertyBuilder

 // Constructs a PropertyBuilder.  
 //
 internal PropertyBuilder(
     ModuleBuilder       mod,            // the module containing this PropertyBuilder
     String              name,           // property name
     SignatureHelper     sig,            // property signature descriptor info
     PropertyAttributes  attr,           // property attribute such as DefaultProperty, Bindable, DisplayBind, etc
     Type                returnType,     // return type of the property.
     PropertyToken       prToken,        // the metadata token for this property
     TypeBuilder         containingType) // the containing type
 {
     if (name == null)
         throw new ArgumentNullException("name");
     if (name.Length == 0)
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     if (name[0] == '\0')
         throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
     Contract.EndContractBlock();
     
     m_name = name;
     m_moduleBuilder = mod;
     m_signature = sig;
     m_attributes = attr;
     m_returnType = returnType;
     m_prToken = prToken;
     m_tkProperty = prToken.Token;
     m_containingType = containingType;
 }
开发者ID:afrog33k,项目名称:csnative,代码行数:28,代码来源:PropertyBuilder.cs


示例16: SymbolMethod

        internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, String methodName, 
            CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
        {
            // This is a kind of MethodInfo to represent methods for array type of unbaked type

            // Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment
            // this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing 
            // passed into it is this MethodToken. The MethodToken was forged using a TypeSpec for an Array type and
            // the name of the method on Array. 
            // As none of the methods on Array have CustomModifiers their is no need to pass those around in here.
            m_mdMethod = token;

            // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders.
            m_returnType = returnType;
            if (parameterTypes != null)
            {
                m_parameterTypes = new Type[parameterTypes.Length];
                Array.Copy(parameterTypes, 0, m_parameterTypes, 0, parameterTypes.Length);
            }
            else
            {
                m_parameterTypes = EmptyArray<Type>.Value; 
            }
   
            m_module = mod;
            m_containingType = arrayClass;
            m_name = methodName;
            m_callingConvention = callingConvention;

            m_signature = SignatureHelper.GetMethodSigHelper(
                mod, callingConvention, returnType, null, null, parameterTypes, null, null);
        }
开发者ID:kouvel,项目名称:coreclr,代码行数:32,代码来源:SymbolMethod.cs


示例17: Build

        internal static TypeBuilder Build(ModuleBuilder proxyModule, Type proxyType,
			 AssemblyDebugging debugAssembly)
        {
            TypeBuilder proxyTypeBuilder = null;
            string proxyName = proxyType.Namespace + "." +
                proxyType.Name + Proxy.ProxyExtension;

            var iProxyType = typeof(IProxy<>).MakeGenericType(proxyType);

            proxyTypeBuilder = proxyModule.DefineType(proxyName,
                 TypeAttributes.Class | TypeAttributes.Sealed |
                 TypeAttributes.Public, proxyType, new Type[] { iProxyType });

            using (TypeDebugging debugType = debugAssembly.GetTypeDebugging(proxyTypeBuilder))
            {
                var fields = ProxyFieldBuilder.Build(
                     proxyTypeBuilder, proxyType);
                ProxyConstructorBuilder.Build(proxyTypeBuilder, proxyType,
                     fields[ProxyFieldBuilder.WrappedObjectField],
                     fields[ProxyFieldBuilder.InvokeHandlerField], debugType);
                ProxyMethodBuilder.Build(proxyTypeBuilder, proxyType, iProxyType,
                     fields[ProxyFieldBuilder.WrappedObjectField],
                     fields[ProxyFieldBuilder.InvokeHandlerField], debugType);
            }

            return proxyTypeBuilder;
        }
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:27,代码来源:ProxyTypeBuilder.cs


示例18: 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


示例19: 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


示例20: XmlILModule

        static XmlILModule() {
            AssemblyName asmName;
            AssemblyBuilder asmBldr;

            CreateModulePermissionSet = new PermissionSet(PermissionState.None);
            // CreateDelegate demands MemberAccess permission
            CreateModulePermissionSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
            // DynamicMethod constructor demands ControlEvidence permissions. 
            // Emitting symbols in DefineDynamicModule (to allow to debug the stylesheet) requires UnmanagedCode permission. 
            CreateModulePermissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.UnmanagedCode));

            AssemblyId = 0;

            // 1. LRE assembly only needs to execute
            // 2. No temp files need be created
            // 3. Never allow assembly to Assert permissions
            asmName = CreateAssemblyName();
            asmBldr = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);

            try {
                CreateModulePermissionSet.Assert();

                // Add custom attribute to assembly marking it as security transparent so that Assert will not be allowed
                // and link demands will be converted to full demands.
                asmBldr.SetCustomAttribute(new CustomAttributeBuilder(XmlILConstructors.Transparent, new object[] {}));

                // Store LREModule once.  If multiple threads are doing this, then some threads might get different
                // modules.  This is OK, since it's not mandatory to share, just preferable.
                LREModule = asmBldr.DefineDynamicModule("System.Xml.Xsl.CompiledQuery", false);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:34,代码来源:XmlILModule.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Emit.OpCode类代码示例发布时间:2022-05-26
下一篇:
C# Emit.MethodBuilder类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap