本文整理汇总了C#中TypeBuilder.RetrieveExactFunctionPointerIfPossible方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.RetrieveExactFunctionPointerIfPossible方法的具体用法?C# TypeBuilder.RetrieveExactFunctionPointerIfPossible怎么用?C# TypeBuilder.RetrieveExactFunctionPointerIfPossible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.RetrieveExactFunctionPointerIfPossible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Prepare
internal unsafe override void Prepare(TypeBuilder builder)
{
_methodToUseForInstantiatingParameters = Method;
IntPtr exactFunctionPointer;
bool canUseRetrieveExactFunctionPointerIfPossible = false;
// RetrieveExactFunctionPointerIfPossible always gets the unboxing stub if possible
if (Method.UnboxingStub)
canUseRetrieveExactFunctionPointerIfPossible = true;
else if (!Method.OwningType.IsValueType) // If the owning type isn't a valuetype, concerns about unboxing stubs are moot
canUseRetrieveExactFunctionPointerIfPossible = true;
else if (TypeLoaderEnvironment.Instance.IsStaticMethodSignature(MethodSignature)) // Static methods don't have unboxing stub concerns
canUseRetrieveExactFunctionPointerIfPossible = true;
if (canUseRetrieveExactFunctionPointerIfPossible &&
builder.RetrieveExactFunctionPointerIfPossible(Method, out exactFunctionPointer))
{
// If we succeed in finding a non-shareable function pointer for this method, it means
// that we found a method body for it that was statically compiled. We'll use that body
// instead of the universal canonical method pointer
Debug.Assert(exactFunctionPointer != IntPtr.Zero &&
exactFunctionPointer != Method.FunctionPointer &&
exactFunctionPointer != Method.UsgFunctionPointer);
_exactFunctionPointer = exactFunctionPointer;
}
else
{
// There is no exact function pointer available. This means that we'll have to
// build a method dictionary for the method instantiation, and use the shared canonical
// function pointer that was parsed from native layout.
_exactFunctionPointer = IntPtr.Zero;
builder.PrepareMethod(Method);
// Check whether we have already resolved a canonical or universal match
IntPtr addressToUse;
TypeLoaderEnvironment.MethodAddressType foundAddressType;
if (Method.FunctionPointer != IntPtr.Zero)
{
addressToUse = Method.FunctionPointer;
foundAddressType = TypeLoaderEnvironment.MethodAddressType.Canonical;
}
else if (Method.UsgFunctionPointer != IntPtr.Zero)
{
addressToUse = Method.UsgFunctionPointer;
foundAddressType = TypeLoaderEnvironment.MethodAddressType.UniversalCanonical;
}
else
{
// No previous match, new lookup is needed
IntPtr fnptr;
IntPtr unboxingStub;
MethodDesc searchMethod = Method;
if (Method.UnboxingStub)
{
// Find the function that isn't an unboxing stub, note the first parameter which is false
searchMethod = searchMethod.Context.ResolveGenericMethodInstantiation(false, (DefType)Method.OwningType, Method.NameAndSignature, Method.Instantiation, IntPtr.Zero, false);
}
if (!TypeLoaderEnvironment.TryGetMethodAddressFromMethodDesc(searchMethod, out fnptr, out unboxingStub, out foundAddressType))
{
Environment.FailFast("Unable to find method address for method:" + Method.ToString());
}
if (Method.UnboxingStub)
{
addressToUse = unboxingStub;
}
else
{
addressToUse = fnptr;
}
if (foundAddressType == TypeLoaderEnvironment.MethodAddressType.Canonical ||
foundAddressType == TypeLoaderEnvironment.MethodAddressType.UniversalCanonical)
{
// Cache the resolved canonical / universal pointer in the MethodDesc
// Actually it would simplify matters here if the MethodDesc held just one pointer
// and the lookup type enumeration value.
Method.SetFunctionPointer(
addressToUse,
foundAddressType == TypeLoaderEnvironment.MethodAddressType.UniversalCanonical);
}
}
// Look at the resolution type and check whether we can set up the ExactFunctionPointer upfront
switch (foundAddressType)
{
case TypeLoaderEnvironment.MethodAddressType.Exact:
_exactFunctionPointer = addressToUse;
break;
case TypeLoaderEnvironment.MethodAddressType.Canonical:
{
bool methodRequestedIsCanonical = Method.IsCanonicalMethod(CanonicalFormKind.Specific);
bool requestedMethodNeedsDictionaryWhenCalledAsCanonical = NeedsDictionaryParameterToCallCanonicalVersion(Method);
if (!requestedMethodNeedsDictionaryWhenCalledAsCanonical || methodRequestedIsCanonical)
//.........这里部分代码省略.........