本文整理汇总了C#中Internal.TypeSystem.MethodDesc.GetTypicalMethodDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDesc.GetTypicalMethodDefinition方法的具体用法?C# MethodDesc.GetTypicalMethodDefinition怎么用?C# MethodDesc.GetTypicalMethodDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internal.TypeSystem.MethodDesc
的用法示例。
在下文中一共展示了MethodDesc.GetTypicalMethodDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsMethodInCompilationGroup
public override bool IsMethodInCompilationGroup(MethodDesc method)
{
if (method.GetTypicalMethodDefinition().ContainsGenericVariables)
return true;
return IsTypeInCompilationGroup(method.OwningType);
}
示例2: ContainsMethod
public override bool ContainsMethod(MethodDesc method)
{
if (method.GetTypicalMethodDefinition().ContainsGenericVariables)
return true;
return ContainsType(method.OwningType);
}
示例3: 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;
}
}
示例4: TryGetMethodAddressFromTypeSystemMethodViaInvokeMap
/// <summary>
/// Resolve a MethodDesc to a callable method address and unboxing stub address by searching
/// by searching in the InvokeMaps. This function is a wrapper around TryGetMethodInvokeDataFromInvokeMap
/// that produces output in the format which matches the code table system.
/// </summary>
/// <param name="method">Native metadata method description object</param>
/// <param name="methodAddress">Resolved method address</param>
/// <param name="unboxingStubAddress">Resolved unboxing stub address</param>
/// <returns>true when the resolution succeeded, false when not</returns>
private static bool TryGetMethodAddressFromTypeSystemMethodViaInvokeMap(
MethodDesc method,
out IntPtr methodAddress,
out IntPtr unboxingStubAddress,
out MethodAddressType foundAddressType)
{
methodAddress = IntPtr.Zero;
unboxingStubAddress = IntPtr.Zero;
foundAddressType = MethodAddressType.None;
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
NativeFormatMethod nativeFormatMethod = method.GetTypicalMethodDefinition() as NativeFormatMethod;
if (nativeFormatMethod == null)
return false;
MethodSignatureComparer methodSignatureComparer = new MethodSignatureComparer(
nativeFormatMethod.MetadataReader, nativeFormatMethod.Handle);
// Try to find a specific canonical match, or if that fails, a universal match
if (TryGetMethodInvokeDataFromInvokeMap(
nativeFormatMethod,
method,
ref methodSignatureComparer,
CanonicalFormKind.Specific,
out methodAddress,
out foundAddressType) ||
TryGetMethodInvokeDataFromInvokeMap(
nativeFormatMethod,
method,
ref methodSignatureComparer,
CanonicalFormKind.Universal,
out methodAddress,
out foundAddressType))
{
if (method.OwningType.IsValueType && !method.Signature.IsStatic)
{
// In this case the invoke map found an unboxing stub, and we should pull the method address out as well
unboxingStubAddress = methodAddress;
methodAddress = RuntimeAugments.GetCodeTarget(unboxingStubAddress);
if (!method.HasInstantiation && ((foundAddressType != MethodAddressType.Exact) || method.OwningType.IsCanonicalSubtype(CanonicalFormKind.Any)))
{
IntPtr underlyingTarget; // unboxing and instantiating stub handling
if (!TypeLoaderEnvironment.TryGetTargetOfUnboxingAndInstantiatingStub(methodAddress, out underlyingTarget))
{
Environment.FailFast("Expected this to be an unboxing and instantiating stub.");
}
methodAddress = underlyingTarget;
}
}
return true;
}
#endif
return false;
}
示例5: FindMethodOnExactTypeWithMatchingTypicalMethod
static private MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method)
{
// Assert that either type is instantiated and its type definition is the type that defines the typical
// method definition of method, or that the owning type of the method typical definition is exactly type
Debug.Assert((type is InstantiatedType) ?
((InstantiatedType)type).GetTypeDefinition() == method.GetTypicalMethodDefinition().OwningType :
type == method.GetTypicalMethodDefinition().OwningType);
MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition();
foreach (MethodDesc methodToExamine in type.GetMethods())
{
if (methodToExamine.GetTypicalMethodDefinition() == methodTypicalDefinition)
return methodToExamine;
}
Debug.Assert(false, "Behavior of typical type not as expected.");
return null;
}
示例6: InstantiatedMethodIL
public InstantiatedMethodIL(MethodDesc owningMethod, MethodIL methodIL)
{
Debug.Assert(methodIL.GetMethodILDefinition() == methodIL);
Debug.Assert(owningMethod.HasInstantiation || owningMethod.OwningType.HasInstantiation);
Debug.Assert(owningMethod.GetTypicalMethodDefinition() == methodIL.OwningMethod);
_methodIL = methodIL;
_method = owningMethod;
_typeInstantiation = owningMethod.OwningType.Instantiation;
_methodInstantiation = owningMethod.Instantiation;
}
示例7: FindMethodOnExactTypeWithMatchingTypicalMethod
static private MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method)
{
MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition();
var instantiatedType = type as InstantiatedType;
if (instantiatedType != null)
{
Debug.Assert(instantiatedType.GetTypeDefinition() == methodTypicalDefinition.OwningType);
return method.Context.GetMethodForInstantiatedType(methodTypicalDefinition, instantiatedType);
}
else
{
Debug.Assert(type == methodTypicalDefinition.OwningType);
return methodTypicalDefinition;
}
}
示例8: FindMethodOnExactTypeWithMatchingTypicalMethod
static internal MethodDesc FindMethodOnExactTypeWithMatchingTypicalMethod(this TypeDesc type, MethodDesc method)
{
MethodDesc methodTypicalDefinition = method.GetTypicalMethodDefinition();
var instantiatedType = type as InstantiatedType;
if (instantiatedType != null)
{
Debug.Assert(instantiatedType.GetTypeDefinition() == methodTypicalDefinition.OwningType);
return method.Context.GetMethodForInstantiatedType(methodTypicalDefinition, instantiatedType);
}
else if (type.IsArray)
{
Debug.Assert(method.OwningType.IsArray);
return ((ArrayType)type).GetArrayMethod(((ArrayMethod)method).Kind);
}
else
{
Debug.Assert(type == methodTypicalDefinition.OwningType);
return methodTypicalDefinition;
}
}
示例9: ComputeMangledMethodName
private string ComputeMangledMethodName(MethodDesc method)
{
string prependTypeName = null;
if (!_mangleForCplusPlus)
prependTypeName = GetMangledTypeName(method.OwningType);
if (method is EcmaMethod)
{
var deduplicator = new HashSet<string>();
// Add consistent names for all methods of the type, independent on the order in which
// they are compiled
lock (this)
{
foreach (var m in method.OwningType.GetMethods())
{
string name = SanitizeName(m.Name);
name = DisambiguateName(name, deduplicator);
deduplicator.Add(name);
if (prependTypeName != null)
name = prependTypeName + "__" + name;
_mangledMethodNames = _mangledMethodNames.Add(m, name);
}
}
return _mangledMethodNames[method];
}
string mangledName;
var methodDefinition = method.GetTypicalMethodDefinition();
if (methodDefinition != method)
{
mangledName = GetMangledMethodName(methodDefinition.GetMethodDefinition());
var inst = method.Instantiation;
for (int i = 0; i < inst.Length; i++)
{
string instArgName = GetMangledTypeName(inst[i]);
if (_mangleForCplusPlus)
instArgName = instArgName.Replace("::", "_");
mangledName += "__" + instArgName;
}
}
else
{
// Assume that Name is unique for all other methods
mangledName = SanitizeName(method.Name);
}
if (prependTypeName != null)
mangledName = prependTypeName + "__" + mangledName;
lock (this)
{
_mangledMethodNames = _mangledMethodNames.Add(method, mangledName);
}
return mangledName;
}
示例10: CreateMethodCell
internal static GenericDictionaryCell CreateMethodCell(MethodDesc method, bool exactCallableAddressNeeded)
{
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
var nativeFormatMethod = (TypeSystem.NativeFormat.NativeFormatMethod)method.GetTypicalMethodDefinition();
return new MethodCell
{
ExactCallableAddressNeeded = exactCallableAddressNeeded,
Method = method,
MethodSignature = RuntimeMethodSignature.CreateFromMethodHandle(nativeFormatMethod.MetadataUnit.RuntimeModule, nativeFormatMethod.Handle.ToInt())
};
#else
Environment.FailFast("Creating a methodcell from a MethodDesc only supported in the presence of metadata based type loading.");
return null;
#endif
}
示例11: GetParameterNamesForMethod
public IEnumerable<string> GetParameterNamesForMethod(MethodDesc method)
{
EcmaMethod ecmaMethod = method.GetTypicalMethodDefinition() as EcmaMethod;
if (ecmaMethod == null)
yield break;
ParameterHandleCollection parameters = ecmaMethod.MetadataReader.GetMethodDefinition(ecmaMethod.Handle).GetParameters();
if (!ecmaMethod.Signature.IsStatic)
{
yield return "_this";
}
foreach (var parameterHandle in parameters)
{
Parameter p = ecmaMethod.MetadataReader.GetParameter(parameterHandle);
yield return ecmaMethod.MetadataReader.GetString(p.Name);
}
}
示例12: GetParameterNamesForMethod
private IEnumerable<string> GetParameterNamesForMethod(MethodDesc method)
{
// TODO: The uses of this method need revision. The right way to get to this info is from
// a MethodIL. For declarations, we don't need names.
method = method.GetTypicalMethodDefinition();
var ecmaMethod = method as EcmaMethod;
if (ecmaMethod != null && ecmaMethod.Module.PdbReader != null)
{
return (new EcmaMethodDebugInformation(ecmaMethod)).GetParameterNames();
}
return null;
}
示例13: TryGetMetadataNativeLayout
/// <summary>
/// Get the NativeLayout for a method from a ReadyToRun image.
/// </summary>
public bool TryGetMetadataNativeLayout(MethodDesc concreteMethod, out IntPtr nativeLayoutInfoModule, out uint nativeLayoutInfoToken)
{
nativeLayoutInfoModule = default(IntPtr);
nativeLayoutInfoToken = 0;
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
var nativeMetadataType = concreteMethod.GetTypicalMethodDefinition() as TypeSystem.NativeFormat.NativeFormatMethod;
if (nativeMetadataType == null)
return false;
var canonForm = concreteMethod.GetCanonMethodTarget(CanonicalFormKind.Specific);
var hashCode = canonForm.GetHashCode();
var loadedModulesCount = RuntimeAugments.GetLoadedModules(null);
var loadedModuleHandles = new IntPtr[loadedModulesCount];
var loadedModules = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
Debug.Assert(loadedModulesCount == loadedModules);
#if SUPPORTS_R2R_LOADING
foreach (var moduleHandle in loadedModuleHandles)
{
ExternalReferencesTable externalFixupsTable;
NativeHashtable methodTemplatesHashtable = LoadHashtable(moduleHandle, ReflectionMapBlob.MetadataBasedGenericMethodsTemplateMap, out externalFixupsTable);
if (methodTemplatesHashtable.IsNull)
continue;
var enumerator = methodTemplatesHashtable.Lookup(hashCode);
var nativeMetadataUnit = nativeMetadataType.Context.ResolveMetadataUnit(moduleHandle);
NativeParser entryParser;
while (!(entryParser = enumerator.GetNext()).IsNull)
{
var entryTypeHandle = entryParser.GetUnsigned().AsHandle();
MethodDesc methodDesc = nativeMetadataUnit.GetMethod(entryTypeHandle, null);
Debug.Assert(methodDesc != null);
if (methodDesc == canonForm)
{
TypeLoaderLogger.WriteLine("Found metadata template for method " + concreteMethod.ToString() + ": " + methodDesc.ToString());
nativeLayoutInfoToken = (uint)externalFixupsTable.GetRvaFromIndex(entryParser.GetUnsigned());
if (nativeLayoutInfoToken == BadTokenFixupValue)
{
throw new BadImageFormatException();
}
nativeLayoutInfoModule = moduleHandle;
return true;
}
}
}
#endif
#endif
return false;
}
示例14: FindMethodOnTypeWithMatchingTypicalMethod
/// <summary>
/// Returns method as defined on a non-generic base class or on a base
/// instantiation.
/// For example, If Foo<T> : Bar<T> and overrides method M,
/// if method is Bar<string>.M(), then this returns Bar<T>.M()
/// but if Foo : Bar<string>, then this returns Bar<string>.M()
/// </summary>
/// <param name="typeExamine">A potentially derived type</param>
/// <param name="method">A base class's virtual method</param>
static public MethodDesc FindMethodOnTypeWithMatchingTypicalMethod(this TypeDesc targetType, MethodDesc method)
{
// If method is nongeneric and on a nongeneric type, then it is the matching method
if (!method.HasInstantiation && !method.OwningType.HasInstantiation)
{
return method;
}
// Since method is an instantiation that may or may not be the same as typeExamine's hierarchy,
// find a matching base class on an open type and then work from the instantiation in typeExamine's
// hierarchy
TypeDesc typicalTypeOfTargetMethod = method.GetTypicalMethodDefinition().OwningType;
TypeDesc targetOrBase = targetType;
do
{
TypeDesc openTargetOrBase = targetOrBase;
if (openTargetOrBase is InstantiatedType)
{
openTargetOrBase = openTargetOrBase.GetTypeDefinition();
}
if (openTargetOrBase == typicalTypeOfTargetMethod)
{
// Found an open match. Now find an equivalent method on the original target typeOrBase
MethodDesc matchingMethod = targetOrBase.FindMethodOnExactTypeWithMatchingTypicalMethod(method);
return matchingMethod;
}
targetOrBase = targetOrBase.BaseType;
} while (targetOrBase != null);
Debug.Assert(false, "method has no related type in the type hierarchy of type");
return null;
}
示例15: GetLocalVariableNamesForMethod
public IEnumerable<LocalVariable> GetLocalVariableNamesForMethod(MethodDesc method)
{
EcmaMethod ecmaMethod = method.GetTypicalMethodDefinition() as EcmaMethod;
if (ecmaMethod == null)
return null;
ModuleData moduleData = _moduleData[ecmaMethod.Module];
if (moduleData.PdbReader == null)
return null;
return _pdbSymbolProvider.GetLocalVariableNamesForMethod(moduleData.PdbReader, MetadataTokens.GetToken(ecmaMethod.Handle));
}