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


C# DefType.RetrieveRuntimeTypeHandleIfPossible方法代码示例

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


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

示例1: GetRuntimeInterfacesAlgorithmForDefType

 protected override RuntimeInterfacesAlgorithm GetRuntimeInterfacesAlgorithmForDefType(DefType type)
 {
     if (type.RetrieveRuntimeTypeHandleIfPossible() && !type.IsGenericDefinition)
     {
         // If the type is already constructed, use the NoMetadataRuntimeInterfacesAlgorithm.
         // its more efficient than loading from native layout or metadata.
         return s_noMetadataRuntimeInterfacesAlgorithm;
     }
     else if (type.HasNativeLayout)
     {
         return s_nativeLayoutInterfacesAlgorithm;
     }
     else if (type is NoMetadataType)
     {
         return s_noMetadataRuntimeInterfacesAlgorithm;
     }
     else if (type is MetadataType)
     {
         return s_metadataRuntimeInterfacesAlgorithm;
     }
     else
     {
         Debug.Assert(false);
         return null;
     }
 }
开发者ID:nattress,项目名称:corert,代码行数:26,代码来源:TypeLoaderTypeSystemContext.cs

示例2: ComputeContainsGCPointers

        public unsafe override bool ComputeContainsGCPointers(DefType type)
        {
            if (type.IsTemplateCanonical())
            {
                return type.ComputeTemplate().RuntimeTypeHandle.ToEETypePtr()->HasGCPointers;
            }
            else
            {
                if (type.RetrieveRuntimeTypeHandleIfPossible())
                {
                    return type.RuntimeTypeHandle.ToEETypePtr()->HasGCPointers;
                }

                return type.GetOrCreateTypeBuilderState().InstanceGCLayout != null;
            }
        }
开发者ID:nattress,项目名称:corert,代码行数:16,代码来源:NativeLayoutFieldAlgorithm.cs

示例3: GetLayoutAlgorithmForType

 public override FieldLayoutAlgorithm GetLayoutAlgorithmForType(DefType type)
 {
     if (type.RetrieveRuntimeTypeHandleIfPossible())
     {
         // If the type is already constructed, use the NoMetadataFieldLayoutAlgorithm.
         // its more efficient than loading from native layout or metadata.
         return s_noMetadataFieldLayoutAlgorithm;
     }
     if (type.HasNativeLayout)
     {
         return s_nativeLayoutFieldAlgorithm;
     }
     else if (type is NoMetadataType)
     {
         return s_noMetadataFieldLayoutAlgorithm;
     }
     else
     {
         return s_metadataFieldLayoutAlgorithm;
     }
 }
开发者ID:nattress,项目名称:corert,代码行数:21,代码来源:TypeLoaderTypeSystemContext.cs

示例4: ResolveVTableSlotIndexToMethodDescOrFunctionPointer

        /// <summary>
        /// Given a type, and vtable slot index, compute either the NativeFormatMethod that defines that vtable slot,
        /// OR the implementation function pointer if the method doesn't have sufficient metadata to be interesting
        /// to use the virtual function resolution algorithm on.
        /// </summary>
        /// <param name="type">Type on which virtual resolution is to be completed</param>
        /// <param name="vtableSlotIndex">Virtual slot index which is to be examined</param>
        /// <param name="functionPointer">If there is no corresponding method defined in metadata, this is
        /// the function pointer that should be used for calls to this vtable slot</param>
        /// <returns>MethodDesc of function that defined the slot if possible.</returns>
        private unsafe static MethodDesc ResolveVTableSlotIndexToMethodDescOrFunctionPointer(DefType type, int vtableSlotIndex, out IntPtr functionPointer)
        {
            Debug.Assert(type.RetrieveRuntimeTypeHandleIfPossible());
            Debug.Assert(type.RuntimeTypeHandle.ToEETypePtr()->NumVtableSlots > vtableSlotIndex);
            DefType definingTypeScan = type;
            DefType previousDefiningType = null;
            EEType* typePtr = null;
            DefType definingType = null;
            functionPointer = IntPtr.Zero;

            while (true)
            {
                definingTypeScan.RetrieveRuntimeTypeHandleIfPossible();
                Debug.Assert(!definingTypeScan.RuntimeTypeHandle.IsNull());
                typePtr = definingTypeScan.RuntimeTypeHandle.ToEETypePtr();
                if (typePtr->NumVtableSlots > vtableSlotIndex)
                {
                    previousDefiningType = definingTypeScan;
                    definingTypeScan = definingTypeScan.BaseType;

                    // We found a slot on System.Object
                    if (definingTypeScan == null)
                    {
                        definingType = previousDefiningType;
                        break;
                    }
                }
                else
                {
                    // We've gone past the type in the type hierarchy that declared this vtable slot
                    // the defining type is the one we looked at previously
                    definingType = previousDefiningType;
                    break;
                }
            }

            // At this point, we know the type that definined the virtual slot
            // There are 4 possibilities here
            //  1. The definingType is a R2R type with full metadata. Compute the MethodDesc, by scanning the list of virtuals present in metadata
            //  2. The definingType is pregenerated, but we can go from the slot index to metadata via the runtime mapping tables. Do so, then run
            //     normal algorithm
            //  3. The definingType is pregenerated, but we cannot go from the slot index to metadata via the runtime mapping tables. There is
            //      only 1 pointer in the vtable of the most derived pregenerated type that has the same value. That's the valuable pointer.
            //  4. The definingType is pregenerated, but we cannot go from the slot index to metadata via the runtime mapping tables. There are
            //      multiple pointers in the vtable of the most derived pregenerated types which have this same value. 
            //         - Take that pointer value, and attempt to resolve back to a method from the implementation. If that succeeds, then 
            //           treat that as the correct vtable slot. Otherwise, return that function pointer. (This is a very rare scenario.)
            MethodDesc slotDefiningMethod = null;
            if (!IsPregeneratedOrTemplateTypeLoaded(definingType))
            {
                // Case 1

                MetadataType definingMetadataType = (MetadataType)definingType;
                int baseTypeSlotCount = 0;

                if (definingMetadataType.BaseType != null)
                    baseTypeSlotCount = definingMetadataType.BaseType.GetRuntimeTypeHandle().ToEETypePtr()->NumVtableSlots;

                int slotOnType = vtableSlotIndex - baseTypeSlotCount;
                Debug.Assert(slotOnType >= 0);

                // R2R types create new slots only for methods that are marked as NewSlot
                if (definingMetadataType.ConvertToCanonForm(CanonicalFormKind.Specific) != definingType)
                {
                    // Deal with the space reserved for the canonical dictionary
                    slotOnType--;
                }
                Debug.Assert(slotOnType >= 0);

                int currentSlot = 0;
                foreach (MethodDesc method in definingMetadataType.GetMethods())
                {
                    if (!MethodDefinesVTableSlot(method))
                        continue;

                    if (currentSlot == slotOnType)
                    {
                        Debug.Assert(VirtualMethodToSlotIndex(method) == vtableSlotIndex);
                        return method;
                    }
                    else
                        currentSlot++;
                }

                Environment.FailFast("Unexpected failure to find virtual function that defined slot");
                return null;
            }
            else if (TryGetVirtualMethodFromSlot(definingType, vtableSlotIndex, out slotDefiningMethod))
            {
                // Case 2
//.........这里部分代码省略.........
开发者ID:nattress,项目名称:corert,代码行数:101,代码来源:LazyVtableResolverThunk.cs


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