MethodInfo GetMethodInfo(IMethod entity)
{
// If method is external, get its existing MethodInfo
var external = entity as ExternalMethod;
if (null != external)
return (MethodInfo)external.MethodInfo;
// If method is a constructed generic method, get its MethodInfo from its definition
if (entity is GenericConstructedMethod)
return GetConstructedMethodInfo(entity.ConstructedInfo);
// If method is mapped from a generic type, get its MethodInfo on the constructed type
var mapped = entity as GenericMappedMethod;
if (mapped != null)
return GetMappedMethodInfo(mapped.DeclaringType, mapped.SourceMember);
// If method is internal, get its MethodBuilder
return GetMethodBuilder(((InternalMethod)entity).Method);
}