MakeGenericType() public method

public MakeGenericType ( ) : System.Type
return System.Type
        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);
        }
 /// <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);
 }
        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);
        }
		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);
		}
Ejemplo n.º 5
0
        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
                }));
        }