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


C# TypeBuilder.DefineGenericParameters方法代码示例

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


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

示例1: MakeGenericType

        private static void MakeGenericType(Type baseType, TypeBuilder typeBuilder) {
            Type[] genericArguments = baseType.GetGenericArguments();
            string[] genericArgumentNames = genericArguments.Select(g => g.Name).ToArray();
            var genericTypeParameterBuilder = typeBuilder.DefineGenericParameters(genericArgumentNames);

            typeBuilder.MakeGenericType(genericTypeParameterBuilder);
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:DynamicTypeBuilder.cs

示例2: MakeGenericType

 /// <summary>
 /// Makes the typeBuilder a generic.
 /// </summary>
 /// <param name="concrete">The concrete.</param>
 /// <param name="typeBuilder">The type builder.</param>
 public static void MakeGenericType(Type baseType, TypeBuilder typeBuilder)
 {
     Type[] genericArguments = baseType.GetGenericArguments();
     string[] genericArgumentNames = GetArgumentNames(genericArguments);
     GenericTypeParameterBuilder[] genericTypeParameterBuilder
         = typeBuilder.DefineGenericParameters(genericArgumentNames);
     typeBuilder.MakeGenericType(genericTypeParameterBuilder);
 }
开发者ID:OleksandrKulchytskyi,项目名称:Sharedeployed,代码行数:13,代码来源:GenericsHelper.cs

示例3: DefineGenericArguments

		public static GenericTypeParameterBuilder[] DefineGenericArguments(
			Type[] genericArguments, TypeBuilder builder,
			Dictionary<String, GenericTypeParameterBuilder> name2GenericType)
		{
			return
				DefineGenericArguments(genericArguments, name2GenericType,
				                       delegate(String[] args) { return builder.DefineGenericParameters(args); });
		}
开发者ID:ralescano,项目名称:castle,代码行数:8,代码来源:GenericUtil.cs

示例4: CopyGenericArguments

		public static GenericTypeParameterBuilder[] CopyGenericArguments(
			MethodInfo methodToCopyGenericsFrom,
			TypeBuilder builder,
			Dictionary<String, GenericTypeParameterBuilder> name2GenericType)
		{
			return
				CopyGenericArguments(methodToCopyGenericsFrom, name2GenericType,
				                       delegate(String[] args) { return builder.DefineGenericParameters(args); });
		}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:9,代码来源:GenericUtil.cs

示例5: MakeGenericType

        internal static Type MakeGenericType(this Type type, TypeBuilder typeBuilder) {
            GenericTypeParameterBuilder[] genericTypeParameterBuilder = null;
            Type[] genericArguments = type.GetGenericArguments();
            string[] genericParameters = genericArguments.Select(g => g.Name)
                                                         .ToArray();

            genericTypeParameterBuilder = typeBuilder.DefineGenericParameters(genericParameters);

            return typeBuilder.MakeGenericType(genericTypeParameterBuilder);
        }
开发者ID:sagifogel,项目名称:NJection.ExpressionSerialization,代码行数:10,代码来源:ReflectionExtensions.cs

示例6: SetUp

		void SetUp (AssemblyBuilderAccess access)
		{
			AssemblyName assemblyName = new AssemblyName ();
			assemblyName.Name = ASSEMBLY_NAME;

			assembly = AppDomain.CurrentDomain.DefineDynamicAssembly (
				assemblyName, access,
				Path.GetTempPath ());

			module = assembly.DefineDynamicModule ("module1");

			tb = module.DefineType ("Bar");
			GenericTypeParameterBuilder [] typeParams = tb.DefineGenericParameters ("T");

			cb = tb.DefineConstructor (MethodAttributes.Public,
				CallingConventions.Standard,
				new Type [] { typeof (string), typeof (int) });
			ILGenerator ig = cb.GetILGenerator ();
			ig.Emit (OpCodes.Ret);

			typeBarOfInt32 = tb.MakeGenericType (typeof (int));
			ci = TypeBuilder.GetConstructor (typeBarOfInt32, cb);
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:23,代码来源:ConstructorOnTypeBuilderInstTest.cs

示例7: CompileInGeneratingFunction

        private void CompileInGeneratingFunction()
        {
            InClass = utilityClass.DefineNestedType(Constants.InGeneratingFunctionClassName,
                TypeAttributes.Sealed | TypeAttributes.Class | TypeAttributes.NestedPublic);

            var genericParameters = declaration.TypeParameters.Any() ? InClass.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var greatestFixedPoint = declaration.TypeParameters.Any()
                ? TypeBuilder.MakeGenericType(genericParameters)
                : TypeBuilder;

            var fGreatestFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, greatestFixedPoint, genericParameters, runtimeContainer);

            InClass.AddInterfaceImplementation(GreatestFixedPointFunction.MakeGenericType(new[] { fGreatestFixedPoint }.Concat(genericParameters).ToArray()));

            InGeneratingFunctionConstructor = InClass.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, TypeBuilder.EmptyTypes);
            var inCtorBody = InGeneratingFunctionConstructor.GetILGenerator();
            inCtorBody.Emit(OpCodes.Ldarg_0);
            inCtorBody.Emit(OpCodes.Call, typeof(object).GetConstructors()[0]);
            inCtorBody.Emit(OpCodes.Ret);

            var apply = InClass.DefineMethod(Constants.ApplyMethodName, MethodAttributes.Public | MethodAttributes.Virtual,
                fGreatestFixedPoint, TypeBuilder.EmptyTypes);

            var genericParameter = apply.DefineGenericParameters(Constants.ApplyMethodGenericParameterName)[0];

            var fGenericParameter = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, genericParameter, genericParameters, runtimeContainer);

            apply.SetParameters(genericParameter, typeof(IFunction<,>).MakeGenericType(genericParameter, fGenericParameter));

            var applyBody = apply.GetILGenerator();
            applyBody.Emit(OpCodes.Ldarg_2);
            applyBody.Emit(OpCodes.Newobj, TypeBuilder.GetConstructor(
               AnaFunction.MakeGenericType(new[] { genericParameter }.Concat(genericParameters).ToArray()),
               AnaFunctionConstructor));
            applyBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new Type[] { genericParameter, greatestFixedPoint }.Concat(genericParameters).ToArray()));
            applyBody.Emit(OpCodes.Ldarg_2);
            applyBody.Emit(OpCodes.Ldarg_1);
            applyBody.Emit(OpCodes.Callvirt, TypeBuilder.GetMethod(
                typeof(IFunction<,>).MakeGenericType(genericParameter, fGenericParameter),
                typeof(IFunction<,>).GetMethod(Constants.CallMethodName)));
            applyBody.Emit(OpCodes.Callvirt, TypeBuilder.GetMethod(
                typeof(IFunction<,>).MakeGenericType(fGenericParameter, fGreatestFixedPoint),
                typeof(IFunction<,>).GetMethod(Constants.CallMethodName)));
            applyBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:46,代码来源:GFixCompiler.cs

示例8: DefineGenericArguments

        private static void DefineGenericArguments(TypeBuilder typeBuilder, Type baseClass)
        {
            if (!baseClass.IsGenericType) return;

            Type[] genericArguments = baseClass.GetGenericArguments();

            GenericTypeParameterBuilder[] genericTypes = typeBuilder.DefineGenericParameters(
                genericArguments.Select(t => t.Name).ToArray());

            for (int i = 0; i < genericArguments.Length; ++i)
            {
                genericTypes[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes);
                foreach (Type constraint in genericArguments[i].GetGenericParameterConstraints())
                {
                    genericTypes[i].SetBaseTypeConstraint(constraint);
                }
            }
        }
开发者ID:shhyder,项目名称:MapApplication,代码行数:18,代码来源:InterceptingClassGenerator.cs

示例9: DefineGenericParameters

        private GenericTypeParameterBuilder[] DefineGenericParameters(TypeBuilder typeBuilder, MethodBuilder methodBuilder, IEnumerable<Cci.IGenericParameter> typeParameters)
        {
            Debug.Assert(typeBuilder != null ^ methodBuilder != null);

            var names = new List<string>(typeParameters.Select(typeParameter => typeParameter.Name)).ToArray();
            var gpBuilders = (typeBuilder != null) ? typeBuilder.DefineGenericParameters(names) : methodBuilder.DefineGenericParameters(names);

            int i = 0;
            foreach (var typeParameter in typeParameters)
            {
                _genericParameterBuilders.Add(typeParameter, gpBuilders[i++]);
            }

            return gpBuilders;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:15,代码来源:ReflectionEmitter.cs

示例10: DefineGenericArguments

        private static GenericParameterMapper DefineGenericArguments(TypeBuilder typeBuilder, Type baseClass)
        {
            if (!baseClass.IsGenericType)
            {
                return GenericParameterMapper.DefaultMapper;
            }
            Type[] genericArguments = baseClass.GetGenericArguments();

            GenericTypeParameterBuilder[] genericTypes = typeBuilder.DefineGenericParameters(
                genericArguments.Select(t => t.Name).ToArray());

            for (int i = 0; i < genericArguments.Length; ++i)
            {
                genericTypes[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes);
                var interfaceConstraints = new List<Type>();
                foreach (Type constraint in genericArguments[i].GetGenericParameterConstraints())
                {
                    if (constraint.IsClass)
                    {
                        genericTypes[i].SetBaseTypeConstraint(constraint);
                    }
                    else
                    {
                        interfaceConstraints.Add(constraint);
                    }
                }
                if (interfaceConstraints.Count > 0)
                {
                    genericTypes[i].SetInterfaceConstraints(interfaceConstraints.ToArray());
                }
            }

            return new GenericParameterMapper(genericArguments, genericTypes.Cast<Type>().ToArray());
        }
开发者ID:kangkot,项目名称:unity,代码行数:34,代码来源:InterceptingClassGenerator.cs

示例11: CompileOutClass

        private void CompileOutClass()
        {
            OutClass = utilityClass.DefineNestedType(Constants.OutClassName,
               TypeAttributes.Sealed | TypeAttributes.Class | TypeAttributes.NestedPublic,
               null, new[] { TypeBuilder });

            var genericParameters = declaration.TypeParameters.Any() ? OutClass.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            var fLeastFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, TypeBuilder, genericParameters, runtimeContainer);

            var predField = OutClass.DefineField(Constants.OutClassPredFieldName, fLeastFixedPoint, FieldAttributes.Private);

            OutClassConstructor = OutClass.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new[] { fLeastFixedPoint });

            var outCtorBody = OutClassConstructor.GetILGenerator();
            outCtorBody.Emit(OpCodes.Ldarg_0);
            outCtorBody.Emit(OpCodes.Call, typeof(object).GetConstructors()[0]);
            outCtorBody.Emit(OpCodes.Ldarg_0);
            outCtorBody.Emit(OpCodes.Ldarg_1);
            outCtorBody.Emit(OpCodes.Stfld, predField);
            outCtorBody.Emit(OpCodes.Ret);

            var cata = OutClass.DefineMethod(Constants.CataMethodName, MethodAttributes.Public | MethodAttributes.Virtual);

            var genericParameter = cata.DefineGenericParameters(Constants.CataMethodGenericParameterName)[0];

            var fGenericParameter = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, genericParameter, genericParameters, runtimeContainer);

            cata.SetParameters(typeof(IFunction<,>).MakeGenericType(fGenericParameter, genericParameter));
            cata.SetReturnType(genericParameter);

            var cataBody = cata.GetILGenerator();
            cataBody.Emit(OpCodes.Ldarg_1);
            cataBody.Emit(OpCodes.Ldarg_1);
            cataBody.Emit(OpCodes.Newobj, TypeBuilder.GetConstructor(CataFunction.MakeGenericType(new[] { genericParameter }.Concat(genericParameters).ToArray()),
                CataFunctionConstructor));
            cataBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new Type[] { TypeBuilder, genericParameter }.Concat(genericParameters).ToArray()));
            cataBody.Emit(OpCodes.Ldarg_0);
            cataBody.Emit(OpCodes.Ldfld, predField);
            cataBody.Emit(OpCodes.Callvirt, TypeBuilder.GetMethod(
                typeof(IFunction<,>).MakeGenericType(fLeastFixedPoint, fGenericParameter),
                typeof(IFunction<,>).GetMethod(Constants.CallMethodName)));
            cataBody.Emit(OpCodes.Callvirt, TypeBuilder.GetMethod(
                typeof(IFunction<,>).MakeGenericType(fGenericParameter, genericParameter),
                typeof(IFunction<,>).GetMethod(Constants.CallMethodName)));
            cataBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:47,代码来源:LFixCompiler.cs

示例12: PreBuild

 protected override void PreBuild()
 {
     if(Info != null)
     {
         return;
     }
     var cont = CurrentContainer;
     Builder = cont.CreateType(Name, Attributes);
     Info = Builder;
     if (Generics.Count > 0)
     {
         var gb = Builder.DefineGenericParameters(Generics.ToNames());
         Generics.RegisterBuilders(gb);
     }
     if (BaseType != null)
     {
         Builder.SetParent(BaseType.GainType()); //todo ジェネリクスに対応したTypeを生成する。
     }
     Builder.AddImplements(Implements);
 }
开发者ID:B-head,项目名称:Dreit-prototype,代码行数:20,代码来源:PureTypeStructure.cs

示例13: AllocateGenericParametersIfNecessary

 private void AllocateGenericParametersIfNecessary(ITypeDefinition typeDefinition, TypeBuilder typeBuilder) {
   if (!typeDefinition.IsGeneric) return;
   //We don't need these to be allocated in this pass, but it is more convenient to do it here.
   var names = new string[typeDefinition.GenericParameterCount];
   foreach (var genericParameter in typeDefinition.GenericParameters)
     names[genericParameter.Index] = genericParameter.Name.Value;
   var genericParameterBuilders = typeBuilder.DefineGenericParameters(names);
   foreach (var genericParameter in typeDefinition.GenericParameters) {
     var genericParameterBuilder = genericParameterBuilders[genericParameter.Index];
     this.loader.builderMap.Add(genericParameter, genericParameterBuilder);
     this.loader.mapper.DefineMapping(genericParameter, genericParameterBuilder);
   }
 }
开发者ID:modulexcite,项目名称:Microsoft.Cci.Metadata,代码行数:13,代码来源:Emitter.cs

示例14: Compile

        public void Compile()
        {
            GreatestFixedPointFunction = module.DefineType(moduleName + '.' + Constants.TypesNamespace + '.' + name + Constants.FunctionSuffix,
                 TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);

            var functionClassGenericParameters = GreatestFixedPointFunction.DefineGenericParameters(new[] { Constants.GFixFunctionClassGenericParameterName }.Concat(declaration.TypeParameters).ToArray());

            GreatestFixedPointFunctionApplyMethod = GreatestFixedPointFunction.DefineMethod(Constants.ApplyMethodName,
                 MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);

            var underlyingType = GreatestFixedPointFunctionApplyMethod.DefineGenericParameters(Constants.ApplyMethodGenericParameterName)[0];

            var functorClass = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, underlyingType,
                functionClassGenericParameters.Skip(1).ToArray(), runtimeContainer);

            GreatestFixedPointFunctionApplyMethod.SetParameters(underlyingType, typeof(IFunction<,>).MakeGenericType(underlyingType, functorClass));
            GreatestFixedPointFunctionApplyMethod.SetReturnType(functionClassGenericParameters[0]);

            TypeBuilder = module.DefineType(moduleName + '.' + Constants.TypesNamespace + '.' + name,
                 TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract);

            var typeGenericParameters = declaration.TypeParameters.Any() ? TypeBuilder.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes;

            GreatestFixedPointApplyMethod = TypeBuilder.DefineMethod(Constants.ApplyMethodName,
                 MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual);

            var resultTypeGfix = GreatestFixedPointApplyMethod.DefineGenericParameters(Constants.GFixFunctionClassGenericParameterName)[0];

            GreatestFixedPointApplyMethod.SetParameters(GreatestFixedPointFunction.MakeGenericType(new[] { resultTypeGfix }.Concat(typeGenericParameters).ToArray()));
            GreatestFixedPointApplyMethod.SetReturnType(resultTypeGfix);

            CompileAnaClass();

            CompileAna();

            CompileAnaFunction();

            CompileAnaFunction1();

            CompileIn();

            CompileInFunction();

            CompileOut();

            CompileOutFunction();

            TypeBuilder.SetCustomAttribute(new CustomAttributeBuilder(
                typeof(InfiniteAttribute).GetConstructors()[0],
                new object[]
                {
                    declaration.ConstructorFunctionName,
                    declaration.DestructorFunctionName,
                    declaration.AnaFunctionName,
                    InFunction
                }));
        }
开发者ID:paf31,项目名称:Purity,代码行数:57,代码来源:GFixCompiler.cs

示例15: CompileCataFunction

        private void CompileCataFunction()
        {
            CataFunction = utilityClass.DefineNestedType(Constants.CataFunctionClassName,
                           TypeAttributes.Sealed | TypeAttributes.Class | TypeAttributes.NestedPublic,
                           null, TypeBuilder.EmptyTypes);

            var genericParameters = CataFunction.DefineGenericParameters(new[] { Constants.CataFunctionClassGenericParameterName }.Concat(declaration.TypeParameters).ToArray());

            var inputParameter = declaration.TypeParameters.Any() ? TypeBuilder.MakeGenericType(genericParameters.Skip(1).ToArray()) : TypeBuilder;

            CataFunction.AddInterfaceImplementation(typeof(IFunction<,>).MakeGenericType(inputParameter, genericParameters[0]));

            var fSeedType = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, genericParameters[0], genericParameters, runtimeContainer);

            var algebra = typeof(IFunction<,>).MakeGenericType(fSeedType, genericParameters[0]);

            var seedField = CataFunction.DefineField(Constants.CataFunctionClassSeedFieldName, algebra, FieldAttributes.Private);

            CataFunctionConstructor = CataFunction.DefineConstructor(MethodAttributes.Public,
                CallingConventions.Standard, new[] { algebra });

            var cataCtorBody = CataFunctionConstructor.GetILGenerator();
            cataCtorBody.Emit(OpCodes.Ldarg_0);
            cataCtorBody.Emit(OpCodes.Call, typeof(object).GetConstructors()[0]);
            cataCtorBody.Emit(OpCodes.Ldarg_0);
            cataCtorBody.Emit(OpCodes.Ldarg_1);
            cataCtorBody.Emit(OpCodes.Stfld, seedField);
            cataCtorBody.Emit(OpCodes.Ret);

            var call = CataFunction.DefineMethod(Constants.CallMethodName, MethodAttributes.Public | MethodAttributes.Virtual,
                genericParameters[0], new Type[] { inputParameter });

            var callBody = call.GetILGenerator();
            callBody.Emit(OpCodes.Ldarg_1);
            callBody.Emit(OpCodes.Ldarg_0);
            callBody.Emit(OpCodes.Ldfld, seedField);
            callBody.Emit(OpCodes.Callvirt, genericParameters.Skip(1).Any()
                ? TypeBuilder.GetMethod(
                    TypeBuilder.MakeGenericType(genericParameters.Skip(1).ToArray()),
                    Cata).MakeGenericMethod(genericParameters[0])
                : Cata.MakeGenericMethod(genericParameters[0]));
            callBody.Emit(OpCodes.Ret);
        }
开发者ID:paf31,项目名称:Purity,代码行数:43,代码来源:LFixCompiler.cs


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