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


C# TypeBuilder.MakeGenericType方法代码示例

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


在下文中一共展示了TypeBuilder.MakeGenericType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

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


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