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


C# TypeDesc.RetrieveRuntimeTypeHandleIfPossible方法代码示例

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


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

示例1: GetFieldGCLayout

        /// <summary>
        /// Get the GC layout of a type when used as a field.
        /// NOTE: if the fieldtype is a reference type, this function will return GCLayout.None
        ///       Consumers of the api must handle that special case.
        /// </summary>
        private unsafe TypeBuilder.GCLayout GetFieldGCLayout(TypeDesc fieldType)
        {
            if (!fieldType.IsValueType)
            {
                if (fieldType.IsPointer)
                    return TypeBuilder.GCLayout.None;
                else
                    return TypeBuilder.GCLayout.SingleReference;
            }

            // Is this a type that already exists? If so, get its gclayout from the EEType directly
            if (fieldType.RetrieveRuntimeTypeHandleIfPossible())
            {
                return new TypeBuilder.GCLayout(fieldType.RuntimeTypeHandle);
            }

            // The type of the field must be a valuetype that is dynamically being constructed

            if (fieldType.IsTemplateCanonical())
            {
                // Pull the GC Desc from the canonical instantiation
                TypeDesc templateType = fieldType.ComputeTemplate();
                bool success = templateType.RetrieveRuntimeTypeHandleIfPossible();
                Debug.Assert(success);
                return new TypeBuilder.GCLayout(templateType.RuntimeTypeHandle);
            }
            else
            {
                // Use the type builder state's computed InstanceGCLayout
                var instanceGCLayout = fieldType.GetOrCreateTypeBuilderState().InstanceGCLayout;
                if (instanceGCLayout == null)
                    return TypeBuilder.GCLayout.None;

                return new TypeBuilder.GCLayout(instanceGCLayout, false /* Always represents a valuetype as the reference type case
                                                                           is handled above with the GCLayout.SingleReference return */);
            }
        }
开发者ID:justinvp,项目名称:corert,代码行数:42,代码来源:TypeBuilderState.cs

示例2: GetFieldSizeAlignment

        internal void GetFieldSizeAlignment(TypeDesc fieldType, out int size, out int alignment)
        {
            Debug.Assert(!fieldType.IsCanonicalSubtype(CanonicalFormKind.Any));

            // All reference and array types are pointer-sized
            if (!fieldType.IsValueType)
            {
                size = IntPtr.Size;
                alignment = IntPtr.Size;
                return;
            }

            // Is this a type that already exists? If so, get its size from the EEType directly
            if (fieldType.RetrieveRuntimeTypeHandleIfPossible())
            {
                unsafe
                {
                    EEType* eeType = fieldType.RuntimeTypeHandle.ToEETypePtr();
                    size = (int)eeType->ValueTypeSize;
                    alignment = eeType->FieldAlignmentRequirement;
                    return;
                }
            }

            // The type of the field must be a generic valuetype that is dynamically being constructed
            Debug.Assert(fieldType.IsValueType);
            DefType fieldDefType = (DefType)fieldType;

            TypeBuilderState state = fieldType.GetOrCreateTypeBuilderState();

            size = fieldDefType.InstanceFieldSize;
            alignment = fieldDefType.InstanceFieldAlignment;
        }
开发者ID:nattress,项目名称:corert,代码行数:33,代码来源:NativeLayoutFieldAlgorithm.cs

示例3: GetInstanceGCLayout

        // Get the GC layout of a type. Handles pre-created, universal template, and non-universal template cases
        // Only to be used for getting the instance layout of non-valuetypes.
        /// <summary>
        /// Get the GC layout of a type. Handles pre-created, universal template, and non-universal template cases
        /// Only to be used for getting the instance layout of non-valuetypes that are used as base types
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private unsafe TypeBuilder.GCLayout GetInstanceGCLayout(TypeDesc type)
        {
            Debug.Assert(!type.IsCanonicalSubtype(CanonicalFormKind.Any));
            Debug.Assert(!type.IsValueType);

            if (type.RetrieveRuntimeTypeHandleIfPossible())
            {
                return new TypeBuilder.GCLayout(type.RuntimeTypeHandle);
            }

            if (type.IsTemplateCanonical())
            {
                var templateType = type.ComputeTemplate();
                bool success = templateType.RetrieveRuntimeTypeHandleIfPossible();
                Debug.Assert(success && !templateType.RuntimeTypeHandle.IsNull());

                return new TypeBuilder.GCLayout(templateType.RuntimeTypeHandle);
            }
            else
            {
                TypeBuilderState state = type.GetOrCreateTypeBuilderState();
                if (state.InstanceGCLayout == null)
                    return TypeBuilder.GCLayout.None;
                else
                    return new TypeBuilder.GCLayout(state.InstanceGCLayout, true);
            }
        }
开发者ID:justinvp,项目名称:corert,代码行数:35,代码来源:TypeBuilderState.cs

示例4: ComputeHasStaticConstructor

 protected internal override bool ComputeHasStaticConstructor(TypeDesc type)
 {
     if (type.RetrieveRuntimeTypeHandleIfPossible())
     {
         unsafe
         {
             return type.RuntimeTypeHandle.ToEETypePtr()->HasCctor;
         }
     }
     else if (type is MetadataType)
     {
         return ((MetadataType)type).GetStaticConstructor() != null;
     }
     return false;
 }
开发者ID:nattress,项目名称:corert,代码行数:15,代码来源:TypeLoaderTypeSystemContext.cs


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