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


C# ModuleBuilder.DefineType方法代码示例

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


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

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

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

示例3: CreateWrappers

 private static void CreateWrappers(Type interfaceType, ModuleBuilder mb,
     out TypeBuilder rawInterface, out TypeBuilder CCP, out TypeBuilder RCP)
 {
     idCounter += 1;
     List<MethodDesc> methodDescs = new List<MethodDesc>();
     foreach (MethodInfo mi in interfaceType.GetMethods())
     {
         methodDescs.Add(new MethodDesc(mi));
     }
     rawInterface = mb.DefineType(interfaceType.FullName + "-RAW" + idCounter, TypeAttributes.Interface);
     CCW = mb.DefineType(interfaceType.FullName + "-CCP" + idCounter, TypeAttributes.Class);
     RCW = mb.DefineType(interfaceType.FullName + "-RCP" + idCounter, TypeAttributes.Class);
 }
开发者ID:poizan42,项目名称:MarshalPlan,代码行数:13,代码来源:MarshalPlanMarshal.cs

示例4: GenerateAnonymousType

        private Type GenerateAnonymousType(ModuleBuilder dynamicTypeModule)
        {
            var dynamicType = dynamicTypeModule.DefineType(ClassName, TypeAttributes.BeforeFieldInit | TypeAttributes.Sealed);
            var builderArray = dynamicType.DefineGenericParameters(GenericClassParameterNames);
            var fields = new List<FieldBuilder>();
            for (var i = 0; i < FieldNames.Length; i++)
            {
                var item = dynamicType.DefineField(FieldNames[i], builderArray[i], FieldAttributes.InitOnly | FieldAttributes.Private);
                var type = typeof(DebuggerBrowsableAttribute);
                var customBuilder = new CustomAttributeBuilder(type.GetConstructor(new Type[] { typeof(DebuggerBrowsableState) }), new object[] { DebuggerBrowsableState.Never });
                item.SetCustomAttribute(customBuilder);
                fields.Add(item);
            }
            var list2 = new List<PropertyBuilder>();
            for (var j = 0; j < PropertyNames.Length; j++)
            {
                var builder4 = GenerateProperty(dynamicType, PropertyNames[j], fields[j]);
//                var type = typeof(JsonPropertyAttribute);
//                var customBuilder2 = new CustomAttributeBuilder(type.GetConstructor(new Type[0]), new object[0]);
//                builder4.SetCustomAttribute(customBuilder2);
                list2.Add(builder4);
            }
            GenerateClassAttributes(dynamicType, PropertyNames);
            GenerateConstructor(dynamicType, PropertyNames, fields);
            GenerateEqualsMethod(dynamicType, fields.ToArray());
            GenerateGetHashCodeMethod(dynamicType, fields.ToArray());
            GenerateToStringMethod(dynamicType, PropertyNames, fields.ToArray());
            return dynamicType.CreateType().MakeGenericType(PropertyTypes);
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:29,代码来源:AnonymousTypeBuilder.cs

示例5: DefineParallelizedType

        public Type DefineParallelizedType(ModuleBuilder moduleBuilder)
        {
            TypeBuilder typeBuilder = moduleBuilder.DefineType(ParallelizedTypeName);
            typeBuilder.SetParent(source);

            TypeAnalyzer typeAnalyzer = new TypeAnalyzer(source);
            ChannelImplementer channelImplementer = new ChannelImplementer(typeBuilder);
            ForkImplementer forkImplementer = new ForkImplementer(typeBuilder, channelImplementer);
            ChordImplementer chordImplementer = new ChordImplementer(typeBuilder, channelImplementer);
            JoinImplementer joinImplementer = new JoinImplementer(typeBuilder, channelImplementer);
            YieldImplementer yieldImplementer = new YieldImplementer(typeBuilder, channelImplementer);
            DisposeImplementer disposeImplementer = new DisposeImplementer(typeBuilder, source);
            ConstructorImplementer constructorImplementer = new ConstructorImplementer(typeBuilder, source,
                                                                                       channelImplementer,
                                                                                       chordImplementer,
                                                                                       disposeImplementer);

            foreach (ForkGroup forkGroup in typeAnalyzer.GetForkGroups())
                forkImplementer.Implement(forkGroup);

            foreach (ChordInfo chord in typeAnalyzer.GetChords())
                chordImplementer.Implement(chord);

            foreach (JoinGroup joinGroup in typeAnalyzer.GetJoinGroups())
                joinImplementer.Implement(joinGroup);

            foreach (YieldInfo yieldInfo in typeAnalyzer.GetYields())
                yieldImplementer.Implement(yieldInfo);

            disposeImplementer.ImplementDisposalBehavior();
            constructorImplementer.ImplementConstructor();

            return typeBuilder.CreateType();
        }
开发者ID:Noah1989,项目名称:fmacj,代码行数:34,代码来源:TypeParallelizer.cs

示例6: SerializerEmitter

		/// <summary>
		/// Initializes a new instance of the <see cref="SerializerEmitter"/> class.
		/// </summary>
		/// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="baseClass">Type of the base class of the serializer.</param>
		/// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
		public SerializerEmitter( ModuleBuilder host, SerializerSpecification specification, Type baseClass, bool isDebuggable )
		{
			Contract.Requires( host != null );
			Contract.Requires( specification != null );
			Contract.Requires( baseClass != null );

			Tracer.Emit.TraceEvent( Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName );

			this._methodTable = new Dictionary<string, MethodBuilder>();
			this._fieldTable = new Dictionary<string, FieldBuilder>();
			this._specification = specification;
			this._host = host;
			this._typeBuilder =
				host.DefineType(
					specification.SerializerTypeFullName,
					TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.UnicodeClass | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit,
					baseClass
				);

#if DEBUG
			Contract.Assert( this._typeBuilder.BaseType != null, "baseType != null" );
#endif // DEBUG
			this._isDebuggable = isDebuggable;

#if DEBUG && !NETFX_35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
			if ( isDebuggable && SerializerDebugging.DumpEnabled )
			{
				SerializerDebugging.PrepareDump( host.Assembly as AssemblyBuilder );
			}
#endif // DEBUG && !NETFX_35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
		}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:38,代码来源:SerializerEmitter.cs

示例7: EmitType

        void EmitType(ModuleBuilder Parent, CodeTypeDeclaration Decl)
        {
            TypeBuilder Type = Parent.DefineType(Decl.Name, TypeAttributes.Public);

            // Allow for late binding
            var LocalMethods = new Dictionary<string, MethodWriter>();
            var LocalParameters = new Dictionary<string, Type[]>();

            foreach(CodeMemberMethod Method in Decl.Members)
            {
                var Writer = new MethodWriter(Type, Method, Methods, Mirror);
                LocalParameters.Add(Method.Name, GetParameterTypes(Method.Parameters));
                LocalMethods.Add(Method.Name, Writer);
            }

            foreach(var Writer in LocalMethods.Values)
            {
                Writer.ParameterTypes = LocalParameters;
                Writer.Methods = LocalMethods;
                Writer.Emit();
                if(Writer.IsEntryPoint) EntryPoint = Writer.Method;
            }

            Type.CreateType();
        }
开发者ID:BillTheBest,项目名称:IronAHK,代码行数:25,代码来源:TypeEmitter.cs

示例8: DefineDelegateType

        /// <summary>
        /// Defines a new delegate type.
        /// </summary>
        public static System.Type DefineDelegateType(
            string fullTypeName,
            ModuleBuilder moduleBuilder,
            System.Type returnType,
            System.Type[] parameterTypes)
        {
            TypeBuilder delegateBuilder =
                moduleBuilder.DefineType(
                    fullTypeName,
                    TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.AnsiClass |
                    TypeAttributes.AutoClass, typeof(MulticastDelegate));

            // Define a special constructor
            ConstructorBuilder constructorBuilder =
                delegateBuilder.DefineConstructor(
                    MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
                    CallingConventions.Standard, new System.Type[] {typeof(object), typeof(IntPtr)});

            constructorBuilder.SetImplementationFlags(
                MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            // Define the Invoke method for the delegate

            MethodBuilder methodBuilder;
            methodBuilder =
                delegateBuilder.DefineMethod(
                    "Invoke",
                    MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot |
                    MethodAttributes.Virtual, returnType, parameterTypes);

            methodBuilder.SetImplementationFlags(
                MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            return delegateBuilder.CreateType();
        }
开发者ID:zibler,项目名称:zibler,代码行数:38,代码来源:EmitUtil.cs

示例9: BuildRedisType

        private static Type BuildRedisType(ModuleBuilder moduleBuilder, Type redisPipelineType)
        {
            const TypeAttributes typeAttributes = TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit;
            const MethodAttributes constructorAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;

            var typeBuilder = moduleBuilder.DefineType("Redis.Dynamic.RedisDynamic", typeAttributes, typeof(RedisBase), Type.EmptyTypes);

            // Emit constructor:
            // public RedisDynamic(IRedisConnection redisConnection)

            var constructorBuilder = typeBuilder.DefineConstructor(constructorAttributes, CallingConventions.Standard, new[] { typeof(IRedisConnection) });
            var redisConstructor = typeof(RedisBase).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(IRedisConnection) }, null);

            var generator = constructorBuilder.GetILGenerator();

            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Call, redisConstructor);
            generator.Emit(OpCodes.Ret);

            // Emit all abstract RedisBase methods

            var redisCommandMethods = typeof(RedisBase).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var redisCommandMethod in redisCommandMethods.Where(x => x.Name != "CreatePipeline" && x.IsAbstract))
            {
                EmitRedisCommandMethod(typeBuilder, redisCommandMethod);
            }

            // Emit CreatePipeline method

            EmitRedisPipelineMethod(typeBuilder, redisPipelineType);

            return typeBuilder.CreateType();
        }
开发者ID:pjtown,项目名称:csharp-redis,代码行数:35,代码来源:RedisTypeBuilder.cs

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

示例11: ILDynamicMethodDebugImpl

 public ILDynamicMethodDebugImpl(string name, Type delegateType, Type thisType)
 {
     _delegateType = delegateType;
     _expectedLength = 64;
     var mi = delegateType.GetMethod("Invoke");
     var uniqueName = ILDynamicTypeDebugImpl.UniqueName(name);
     _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, DynamicILDirectoryPath.DynamicIL);
     _moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
     var sourceCodeFileName = Path.Combine(DynamicILDirectoryPath.DynamicIL, uniqueName + ".il");
     _symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
     _sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
     Type[] parameterTypes;
     if (thisType != null)
     {
         parameterTypes = new[] { thisType }.Concat(mi.GetParameters().Select(pi => pi.ParameterType)).ToArray();
     }
     else
     {
         parameterTypes = mi.GetParameters().Select(pi => pi.ParameterType).ToArray();
     }
     _sourceCodeWriter.StartMethod(name, mi.ReturnType, parameterTypes, MethodAttributes.Static);
     _typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, typeof(object), Type.EmptyTypes);
     _forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
     _dynamicMethod = _typeBuilder.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Static, mi.ReturnType, parameterTypes);
     for (int i = 0; i < parameterTypes.Length; i++)
     {
         _dynamicMethod.DefineParameter(i + 1, ParameterAttributes.In, string.Format("arg{0}", i));
     }
 }
开发者ID:yonglehou,项目名称:BTDB,代码行数:29,代码来源:ILDynamicMethodDebugImpl.cs

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

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

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

示例15: Program

        public void Program()
        {
            var tempName = "EvilProg-" + Guid.NewGuid().ToString();

            AssemblyName aName = new AssemblyName(tempName);
            AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Save);
            programModule = ab.DefineDynamicModule(aName.Name, tempName + ".exe", true);
            programType = programModule.DefineType("Program", TypeAttributes.Public);

            createReadInInt();

            this.program();

            var main = functionMap["main"];

            programModule.SetUserEntryPoint(main);
            ab.SetEntryPoint(main);

            programType.CreateType();

            string tempPath = tempName + ".exe";
            ab.Save(tempPath);

            if (File.Exists(Options.ClrExec.Value))
                File.Delete(Options.ClrExec.Value);

            File.Move(tempPath, Options.ClrExec.Value);
            File.Delete(tempPath);
        }
开发者ID:AustinWise,项目名称:CSC431,代码行数:29,代码来源:StackGen.mine.cs


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