当前位置: 首页>>代码示例>>C#>>正文


C# RuntimeTypeHandle.ToIntPtr方法代码示例

本文整理汇总了C#中System.RuntimeTypeHandle.ToIntPtr方法的典型用法代码示例。如果您正苦于以下问题:C# RuntimeTypeHandle.ToIntPtr方法的具体用法?C# RuntimeTypeHandle.ToIntPtr怎么用?C# RuntimeTypeHandle.ToIntPtr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.RuntimeTypeHandle的用法示例。


在下文中一共展示了RuntimeTypeHandle.ToIntPtr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryGetNonUnboxingFunctionPointerFromUnboxingAndInstantiatingStub

        public static unsafe bool TryGetNonUnboxingFunctionPointerFromUnboxingAndInstantiatingStub(IntPtr potentialStub, RuntimeTypeHandle exactType, out IntPtr nonUnboxingMethod)
        {
            IntPtr callConversionId;
            IntPtr commonStubDataPtr;
            if (!RuntimeAugments.TryGetThunkData(s_thunkPoolHeap, potentialStub, out callConversionId, out commonStubDataPtr))
            {
                // This isn't a call conversion stub
                nonUnboxingMethod = IntPtr.Zero;
                return false;
            }

            CallConversionInfo conversionInfo = CallConversionInfo.GetConverter(callConversionId.ToInt32());
            if (conversionInfo.IsUnboxingThunk)
            {
                // In this case the call converter is serving as an unboxing/instantiating stub
                // This case is not yet handled, and we don't need support for it yet.
                throw NotImplemented.ByDesign;
            }

            IntPtr underlyingTargetMethod;
            IntPtr newInstantiatingArg;

            if (conversionInfo.CalleeHasParamType)
            {
                // In this case the call converter is an instantiating stub wrapping an unboxing thunk.
                // Use the redhawk GetCodeTarget to see through the unboxing stub and get the real underlying method
                // and the instantiation arg does not need changing.
                underlyingTargetMethod = RuntimeAugments.GetCodeTarget(conversionInfo.TargetFunctionPointer);
                newInstantiatingArg = conversionInfo.InstantiatingStubArgument;
            }
            else
            {
                // At this point we've got a standard to generic converter wrapping an unboxing and instantiating
                // stub. We need to convert that into a fat function pointer directly calling the underlying method
                // or a calling convention converter instantiating stub wrapping the underlying method
                IntPtr underlyingUnboxingAndInstantiatingMethod = RuntimeAugments.GetCodeTarget(conversionInfo.TargetFunctionPointer);
                if (!TypeLoaderEnvironment.TryGetTargetOfUnboxingAndInstantiatingStub(underlyingUnboxingAndInstantiatingMethod, out underlyingTargetMethod))
                {
                    // We aren't wrapping an unboxing and instantiating stub. This should never happen
                    throw new NotSupportedException();
                }

                newInstantiatingArg = exactType.ToIntPtr();
            }

            Debug.Assert(conversionInfo.CallerForcedByRefData == null);

            bool canUseFatFunctionPointerInsteadOfThunk = true;
            if (conversionInfo.CalleeForcedByRefData != null)
            {
                foreach (bool forcedByRef in conversionInfo.CalleeForcedByRefData)
                {
                    if (forcedByRef)
                    {
                        canUseFatFunctionPointerInsteadOfThunk = false;
                        break;
                    }
                }
            }

            if (canUseFatFunctionPointerInsteadOfThunk)
            {
                nonUnboxingMethod = FunctionPointerOps.GetGenericMethodFunctionPointer(underlyingTargetMethod, newInstantiatingArg);
                return true;
            }
            else
            {
                // Construct a new StandardToGenericInstantiating thunk around the underlyingTargetMethod
                nonUnboxingMethod = MakeThunk(ThunkKind.StandardToGenericInstantiating,
                                 underlyingTargetMethod,
                                 newInstantiatingArg,
                                 conversionInfo.ArgIteratorData,
                                 conversionInfo.CalleeForcedByRefData);
                return true;
            }
        }
开发者ID:justinvp,项目名称:corert,代码行数:76,代码来源:CallConverterThunk.cs


注:本文中的System.RuntimeTypeHandle.ToIntPtr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。