本文整理汇总了C#中System.Reflection.Emit.MethodBuilder.GetGenericArguments方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBuilder.GetGenericArguments方法的具体用法?C# MethodBuilder.GetGenericArguments怎么用?C# MethodBuilder.GetGenericArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.MethodBuilder
的用法示例。
在下文中一共展示了MethodBuilder.GetGenericArguments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PushTargetMethodInfo
private static void PushTargetMethodInfo(ILGenerator IL, MethodBuilder generatedMethod, MethodInfo method)
{
if (method.IsGenericMethodDefinition)
{
// We want the generated code to load a MethodInfo instantiated with the
// current generic type parameters. I.e.:
// MethodInfo methodInfo = methodof(TheClass.TheMethod<T>(...)
//
// We need to instantiate the open generic method definition with the type
// arguments from the generated method. Using the open method definition
// directly works on .Net 2.0, which might be FW bug, but fails on 4.0.
//
// Equivalent pseudo-code:
// MethodInfo mi = methodof(TheClass.TheMethod<>)
// versus
// MethodInfo mi = methodof(TheClass.TheMethod<T0>)
var instantiatedMethod = method.MakeGenericMethod(generatedMethod.GetGenericArguments());
IL.Emit(OpCodes.Ldtoken, instantiatedMethod);
}
else
{
IL.Emit(OpCodes.Ldtoken, method);
}
System.Type declaringType = method.DeclaringType;
if (declaringType.IsGenericType)
{
IL.Emit(OpCodes.Ldtoken, declaringType);
IL.Emit(OpCodes.Call, getGenericMethodFromHandle);
}
else
{
IL.Emit(OpCodes.Call, getMethodFromHandle);
}
IL.Emit(OpCodes.Castclass, typeof(MethodInfo));
}