本文整理汇总了C#中Internal.TypeSystem.MethodDesc类的典型用法代码示例。如果您正苦于以下问题:C# MethodDesc类的具体用法?C# MethodDesc怎么用?C# MethodDesc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodDesc类属于Internal.TypeSystem命名空间,在下文中一共展示了MethodDesc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: IsMethodInCompilationGroup
public override bool IsMethodInCompilationGroup(MethodDesc method)
{
if (method.GetTypicalMethodDefinition().ContainsGenericVariables)
return true;
return IsTypeInCompilationGroup(method.OwningType);
}
示例3: TryGetPregeneratedPInvoke
/// <summary>
/// Returns pregenerated interop code for given PInvoke method if one exist
/// </summary>
public static MethodDesc TryGetPregeneratedPInvoke(MethodDesc method)
{
Debug.Assert(method.IsPInvoke);
var metadataType = (MetadataType)method.OwningType;
var module = metadataType.Module;
var assemblyName = ((IAssemblyDesc)module).GetName();
var interopAssemblyName = new AssemblyName();
interopAssemblyName.Name = assemblyName.Name + AssemblyNameSuffix;
interopAssemblyName.Version = assemblyName.Version;
interopAssemblyName.SetPublicKeyToken(interopAssemblyName.GetPublicKeyToken());
interopAssemblyName.CultureName = assemblyName.CultureName;
interopAssemblyName.ContentType = assemblyName.ContentType;
var interopModule = module.Context.ResolveAssembly(interopAssemblyName, false);
if (interopModule == null)
return null;
var pregeneratedMethod = GetMatchingMethod(interopModule, method);
if (pregeneratedMethod == null)
{
// TODO: Better error message
throw new MissingMemberException("Missing method in " + interopAssemblyName.Name + ":" + method.ToString());
}
return pregeneratedMethod;
}
示例4: GetMatchingMethod
// Returns null if no matching method is found
private static MethodDesc GetMatchingMethod(ModuleDesc module, MethodDesc method)
{
var matchingType = GetMatchingType(module, method.OwningType);
if (matchingType == null)
return null;
return matchingType.GetMethod(method.Name, method.Signature);
}
示例5: EmitIL
public static MethodIL EmitIL(MethodDesc target)
{
Debug.Assert(target.Name == "EETypePtrOf");
Debug.Assert(target.Signature.Length == 0
&& target.Signature.ReturnType == target.OwningType);
Debug.Assert(target.Instantiation.Length == 1);
ILEmitter emitter = new ILEmitter();
var codeStream = emitter.NewCodeStream();
TypeSystemContext context = target.Context;
TypeDesc runtimeTypeHandleType = context.GetWellKnownType(WellKnownType.RuntimeTypeHandle);
MethodDesc getValueInternalMethod = runtimeTypeHandleType.GetKnownMethod("GetValueInternal", null);
MethodDesc eetypePtrCtorMethod = context.SystemModule
.GetKnownType("System", "EETypePtr")
.GetKnownMethod(".ctor", new MethodSignature(0, 0, context.GetWellKnownType(WellKnownType.Void),
new TypeDesc[] { context.GetWellKnownType(WellKnownType.IntPtr) }));
// The sequence of these instructions is important. JIT is able to optimize out
// the LDTOKEN+GetValueInternal call into "load EEType pointer onto the evaluation stack".
codeStream.Emit(ILOpcode.ldtoken, emitter.NewToken(context.GetSignatureVariable(0, true)));
codeStream.Emit(ILOpcode.call, emitter.NewToken(getValueInternalMethod));
codeStream.Emit(ILOpcode.newobj, emitter.NewToken(eetypePtrCtorMethod));
codeStream.Emit(ILOpcode.ret);
return emitter.Link(target);
}
示例6: FixupCellMetadataResolver
public FixupCellMetadataResolver(NativeFormatMetadataUnit metadataUnit, MethodDesc methodContext)
{
_metadataUnit = metadataUnit;
_methodContext = methodContext;
_typeContext = methodContext.OwningType;
_loadContextFromNativeLayout = null;
}
示例7: FatFunctionPointerNode
public FatFunctionPointerNode(MethodDesc methodRepresented)
{
// We should not create these for methods that don't have a canonical method body
Debug.Assert(methodRepresented.GetCanonMethodTarget(CanonicalFormKind.Specific) != methodRepresented);
Method = methodRepresented;
}
示例8: IsStubRequired
/// <summary>
/// Returns true if <paramref name="method"/> requires a stub to be generated.
/// </summary>
public static bool IsStubRequired(MethodDesc method)
{
Debug.Assert(method.IsPInvoke);
// TODO: true if there are any custom marshalling rules on the parameters
// TODO: true if SetLastError is true
TypeDesc returnType = method.Signature.ReturnType;
if (!IsBlittableType(returnType) && !returnType.IsVoid)
return true;
for (int i = 0; i < method.Signature.Length; i++)
{
if (!IsBlittableType(method.Signature[i]))
{
return true;
}
}
if (UseLazyResolution(method, method.GetPInvokeMethodMetadata().Module))
{
return true;
}
return false;
}
示例9: 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(')');
}
示例10: DelegateInfo
public DelegateInfo(Compilation compilation, MethodDesc target)
{
this.Target = target;
var systemDelegate = compilation.TypeSystemContext.GetWellKnownType(WellKnownType.MulticastDelegate).BaseType;
// TODO: delegates on virtuals
if (target.IsVirtual && !target.IsFinal)
throw new NotImplementedException("Delegate to virtual");
// TODO: Delegates on valuetypes
if (target.OwningType.IsValueType)
throw new NotImplementedException("Delegate to valuetype");
if (target.Signature.IsStatic)
{
this.ShuffleThunk = new DelegateShuffleThunk(target);
this.Ctor = systemDelegate.GetKnownMethod("InitializeClosedStaticThunk", null);
}
else
{
this.Ctor = systemDelegate.GetKnownMethod("InitializeClosedInstance", null);
}
}
示例11: GetVirtualMethodSlot
/// <summary>
/// Given a virtual method decl, return its VTable slot if the method is used on its containing type.
/// Return -1 if the virtual method is not used.
/// </summary>
public static int GetVirtualMethodSlot(NodeFactory factory, MethodDesc method)
{
// TODO: More efficient lookup of the slot
TypeDesc owningType = method.OwningType;
int baseSlots = 0;
var baseType = owningType.BaseType;
while (baseType != null)
{
List<MethodDesc> baseVirtualSlots;
factory.VirtualSlots.TryGetValue(baseType, out baseVirtualSlots);
if (baseVirtualSlots != null)
baseSlots += baseVirtualSlots.Count;
baseType = baseType.BaseType;
}
List<MethodDesc> virtualSlots = factory.VirtualSlots[owningType];
int methodSlot = -1;
for (int slot = 0; slot < virtualSlots.Count; slot++)
{
if (virtualSlots[slot] == method)
{
methodSlot = slot;
break;
}
}
return methodSlot == -1 ? -1 : baseSlots + methodSlot;
}
示例12: Create
/// <summary>
/// Constructs a new instance of <see cref="DelegateCreationInfo"/> set up to construct a delegate of type
/// '<paramref name="delegateType"/>' pointing to '<paramref name="targetMethod"/>'.
/// </summary>
public static DelegateCreationInfo Create(TypeDesc delegateType, MethodDesc targetMethod, NodeFactory factory)
{
var context = (CompilerTypeSystemContext)delegateType.Context;
var systemDelegate = targetMethod.Context.GetWellKnownType(WellKnownType.MulticastDelegate).BaseType;
int paramCountTargetMethod = targetMethod.Signature.Length;
if (!targetMethod.Signature.IsStatic)
{
paramCountTargetMethod++;
}
DelegateInfo delegateInfo = context.GetDelegateInfo(delegateType.GetTypeDefinition());
int paramCountDelegateClosed = delegateInfo.Signature.Length + 1;
bool closed = false;
if (paramCountDelegateClosed == paramCountTargetMethod)
{
closed = true;
}
else
{
Debug.Assert(paramCountDelegateClosed == paramCountTargetMethod + 1);
}
if (targetMethod.Signature.IsStatic)
{
MethodDesc invokeThunk;
if (!closed)
{
// Open delegate to a static method
invokeThunk = delegateInfo.Thunks[DelegateThunkKind.OpenStaticThunk];
}
else
{
// Closed delegate to a static method (i.e. delegate to an extension method that locks the first parameter)
invokeThunk = delegateInfo.Thunks[DelegateThunkKind.ClosedStaticThunk];
}
var instantiatedDelegateType = delegateType as InstantiatedType;
if (instantiatedDelegateType != null)
invokeThunk = context.GetMethodForInstantiatedType(invokeThunk, instantiatedDelegateType);
// We use InitializeClosedStaticThunk for both because RyuJIT generates same code for both,
// but passes null as the first parameter for the open one.
return new DelegateCreationInfo(
factory.MethodEntrypoint(systemDelegate.GetKnownMethod("InitializeClosedStaticThunk", null)),
factory.MethodEntrypoint(targetMethod),
factory.MethodEntrypoint(invokeThunk));
}
else
{
if (!closed)
throw new NotImplementedException("Open instance delegates");
bool useUnboxingStub = targetMethod.OwningType.IsValueType;
return new DelegateCreationInfo(
factory.MethodEntrypoint(systemDelegate.GetKnownMethod("InitializeClosedInstance", null)),
factory.MethodEntrypoint(targetMethod, useUnboxingStub));
}
}
示例13: ContainsMethod
public sealed override bool ContainsMethod(MethodDesc method)
{
if (method.HasInstantiation)
return true;
return ContainsType(method.OwningType);
}
示例14: 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;
}
}
示例15: InitializeMethods
private void InitializeMethods()
{
int numCtors;
if (IsSzArray)
{
numCtors = 1;
var t = this.ElementType;
while (t.IsSzArray)
{
t = ((ArrayType)t).ElementType;
numCtors++;
}
}
else
{
// ELEMENT_TYPE_ARRAY has two ctor functions, one with and one without lower bounds
numCtors = 2;
}
MethodDesc[] methods = new MethodDesc[(int)ArrayMethodKind.Ctor + numCtors];
for (int i = 0; i < methods.Length; i++)
methods[i] = new ArrayMethod(this, (ArrayMethodKind)i);
Interlocked.CompareExchange(ref _methods, methods, null);
}