本文整理汇总了C#中IMethodInfo.GetGenericMethodDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# IMethodInfo.GetGenericMethodDefinition方法的具体用法?C# IMethodInfo.GetGenericMethodDefinition怎么用?C# IMethodInfo.GetGenericMethodDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMethodInfo
的用法示例。
在下文中一共展示了IMethodInfo.GetGenericMethodDefinition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObtainMethod
private static IMethodInfo ObtainMethod(IMethodInfo proxiedMethod, Type type)
{
Type[] genericArguments = null;
if (proxiedMethod.IsGenericMethod)
{
genericArguments = proxiedMethod.GetGenericArguments();
proxiedMethod = proxiedMethod.GetGenericMethodDefinition();
}
var declaringType = proxiedMethod.DeclaringType;
IMethodInfo methodOnTarget = null;
if (declaringType.IsInterface())
{
var mapping = type.GetInterfaceMap(declaringType);
var index = Array.IndexOf(mapping.InterfaceMethods, proxiedMethod);
Debug.Assert(index != -1);
methodOnTarget = mapping.TargetMethods[index].AsIMethodInfo();
}
else
{
// NOTE: this implementation sucks, feel free to improve it.
var methods = MethodFinder.GetAllInstanceMethods(type, BindingFlags.Public | BindingFlags.NonPublic);
foreach (var method in methods)
{
if (MethodSignatureComparer.Instance.Equals(method.GetBaseDefinition(), proxiedMethod))
{
methodOnTarget = method;
break;
}
}
}
if (methodOnTarget == null)
{
throw new ArgumentException(
string.Format("Could not find method overriding {0} on type {1}. This is most likely a bug. Please report it.",
proxiedMethod, type));
}
if (genericArguments == null)
{
return methodOnTarget;
}
return methodOnTarget.MakeGenericMethod(genericArguments);
}