本文整理汇总了C#中Internal.TypeSystem.MethodDesc.GetMethodDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDesc.GetMethodDefinition方法的具体用法?C# MethodDesc.GetMethodDefinition怎么用?C# MethodDesc.GetMethodDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internal.TypeSystem.MethodDesc
的用法示例。
在下文中一共展示了MethodDesc.GetMethodDefinition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMethodIL
public MethodIL GetMethodIL(MethodDesc method)
{
if (method is EcmaMethod)
{
// TODO: Workaround: we should special case methods with Intrinsic attribute, but since
// CoreLib source is still not in the repo, we have to work with what we have, which is
// an MCG attribute on the type itself...
if (((MetadataType)method.OwningType).HasCustomAttribute("System.Runtime.InteropServices", "McgIntrinsicsAttribute"))
{
if (method.Name == "Call")
{
return CalliIntrinsic.EmitIL(method);
}
}
if (method.IsIntrinsic)
{
MethodIL result = TryGetIntrinsicMethodIL(method);
if (result != null)
return result;
}
if (method.IsPInvoke)
{
return PInvokeMarshallingILEmitter.EmitIL(method);
}
return EcmaMethodIL.Create((EcmaMethod)method);
}
else
if (method is MethodForInstantiatedType)
{
var methodDefinitionIL = GetMethodIL(method.GetTypicalMethodDefinition());
if (methodDefinitionIL == null)
return null;
return new InstantiatedMethodIL(methodDefinitionIL, method.OwningType.Instantiation, new Instantiation());
}
else
if (method is InstantiatedMethod)
{
var methodDefinitionIL = GetMethodIL(method.GetMethodDefinition());
if (methodDefinitionIL == null)
return null;
return new InstantiatedMethodIL(methodDefinitionIL, new Instantiation(), method.Instantiation);
}
else
if (method is ILStubMethod)
{
return ((ILStubMethod)method).EmitIL();
}
else
if (method is ArrayMethod)
{
return ArrayMethodILEmitter.EmitIL((ArrayMethod)method);
}
else
{
return null;
}
}
示例2: AppendMethodSignature
private void AppendMethodSignature(StringBuilder sb, MethodDesc method)
{
// If this is an instantiated generic method, the formatted signature should
// be uninstantiated (e.g. "void Foo::Bar<int>(!!0 param)", not "void Foo::Bar<int>(int param)")
MethodSignature signature = method.GetMethodDefinition().Signature;
AppendSignaturePrefix(sb, signature);
sb.Append(' ');
AppendOwningType(sb, method.OwningType);
sb.Append("::");
sb.Append(method.Name);
if (method.HasInstantiation)
{
sb.Append('<');
for (int i = 0; i < method.Instantiation.Length; i++)
{
if (i != 0)
sb.Append(", ");
_typeNameFormatter.AppendNameWithValueClassPrefix(sb, method.Instantiation[i]);
}
sb.Append('>');
}
sb.Append('(');
AppendSignatureArgumentList(sb, signature);
sb.Append(')');
}
示例3: TryResolveConstraintMethodApprox
/// <summary>
/// Attempts to resolve constrained call to <paramref name="interfaceMethod"/> into a concrete non-unboxing
/// method on <paramref name="constrainedType"/>.
/// The ability to resolve constraint methods is affected by the degree of code sharing we are performing
/// for generic code.
/// </summary>
/// <returns>The resolved method or null if the constraint couldn't be resolved.</returns>
static public MethodDesc TryResolveConstraintMethodApprox(this MetadataType constrainedType, TypeDesc interfaceType, MethodDesc interfaceMethod, out bool forceRuntimeLookup)
{
forceRuntimeLookup = false;
// We can't resolve constraint calls effectively for reference types, and there's
// not a lot of perf. benefit in doing it anyway.
if (!constrainedType.IsValueType)
{
return null;
}
// Non-virtual methods called through constraints simply resolve to the specified method without constraint resolution.
if (!interfaceMethod.IsVirtual)
{
return null;
}
MetadataType canonMT = constrainedType;
MethodDesc method;
MethodDesc genInterfaceMethod = interfaceMethod.GetMethodDefinition();
if (genInterfaceMethod.OwningType.IsInterface)
{
// Sometimes (when compiling shared generic code)
// we don't have enough exact type information at JIT time
// even to decide whether we will be able to resolve to an unboxed entry point...
// To cope with this case we always go via the helper function if there's any
// chance of this happening by checking for all interfaces which might possibly
// be compatible with the call (verification will have ensured that
// at least one of them will be)
// Enumerate all potential interface instantiations
// TODO: this code assumes no shared generics
Debug.Assert(interfaceType == interfaceMethod.OwningType);
method = VirtualFunctionResolution.ResolveInterfaceMethodToVirtualMethodOnType(genInterfaceMethod, constrainedType);
}
else if (genInterfaceMethod.IsVirtual)
{
method = VirtualFunctionResolution.FindVirtualFunctionTargetMethodOnObjectType(genInterfaceMethod, constrainedType);
}
else
{
// The method will be null if calling a non-virtual instance
// methods on System.Object, i.e. when these are used as a constraint.
method = null;
}
if (method == null)
{
// Fall back to VSD
return null;
}
//#TryResolveConstraintMethodApprox_DoNotReturnParentMethod
// Only return a method if the value type itself declares the method,
// otherwise we might get a method from Object or System.ValueType
if (!method.OwningType.IsValueType)
{
// Fall back to VSD
return null;
}
// We've resolved the method, ignoring its generic method arguments
// If the method is a generic method then go and get the instantiated descriptor
if (interfaceMethod.HasInstantiation)
{
method = method.InstantiateSignature(interfaceType.Instantiation, interfaceMethod.Instantiation);
}
Debug.Assert(method != null);
//assert(!pMD->IsUnboxingStub());
return method;
}