本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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
}));
}