protected virtual MethodInfo GetMethodImpl()
{
if (_methodBase == null)
{
RuntimeMethodHandle method = FindMethodHandle();
RuntimeTypeHandle declaringType = method.GetDeclaringType();
// need a proper declaring type instance method on a generic type
if (declaringType.IsGenericTypeDefinition() || declaringType.HasInstantiation())
{
bool isStatic = (method.GetAttributes() & MethodAttributes.Static) != (MethodAttributes)0;
if (!isStatic)
{
if (_methodPtrAux == (IntPtr)0)
{
declaringType = _target.GetType().TypeHandle; // may throw NullRefException if the this is null but that's ok
}
else
{
// it's an open one, need to fetch the first arg of the instantiation
MethodInfo invoke = this.GetType().GetMethod("Invoke");
declaringType = invoke.GetParameters()[0].ParameterType.TypeHandle;
}
}
}
_methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method);
}
return((MethodInfo)_methodBase);
}