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


C# DefType.IsTemplateUniversal方法代码示例

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


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

示例1: ComputeInstanceLayout

        public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType type, InstanceLayoutKind layoutKind)
        {
            if (!type.IsTemplateUniversal() && (layoutKind == InstanceLayoutKind.TypeOnly))
            {
                // Non universal generics can just use the template's layout
                DefType template = (DefType)type.ComputeTemplate();
                return _noMetadataFieldLayoutAlgorithm.ComputeInstanceLayout(template, InstanceLayoutKind.TypeOnly);
            }

            // Only needed for universal generics, or when looking up an offset for a field for a universal generic
            LowLevelList<int> fieldOffsets;
            int[] position = ComputeTypeSizeAndAlignment(type, FieldLoadState.Instance, out fieldOffsets);

            int numInstanceFields = 0;
            foreach (NativeLayoutFieldDesc field in type.NativeLayoutFields)
            {
                if (!field.IsStatic)
                {
                    numInstanceFields++;
                }
            }

            int byteCountAlignment = position[InstanceAlignmentEntry];
            byteCountAlignment = type.Context.Target.GetObjectAlignment(byteCountAlignment);

            ComputedInstanceFieldLayout layout = new ComputedInstanceFieldLayout()
            {
                Offsets = new FieldAndOffset[numInstanceFields],
                ByteCountAlignment = byteCountAlignment,
                ByteCountUnaligned = position[(int)NativeFormat.FieldStorage.Instance],
                PackValue = 0 // TODO, as we add more metadata handling logic, find out if its necessary to use a meaningful value here
            };

            if (!type.IsValueType)
            {
                layout.FieldAlignment = type.Context.Target.PointerSize;
                layout.FieldSize = type.Context.Target.PointerSize;
            }
            else
            {
                layout.FieldAlignment = position[InstanceAlignmentEntry];
                layout.FieldSize = MemoryHelpers.AlignUp(position[(int)NativeFormat.FieldStorage.Instance], layout.FieldAlignment);
            }

            int curInstanceField = 0;
            foreach (NativeLayoutFieldDesc field in type.NativeLayoutFields)
            {
                if (!field.IsStatic)
                {
                    layout.Offsets[curInstanceField] = new FieldAndOffset(field, fieldOffsets[curInstanceField]);
                    curInstanceField++;
                }
            }

            return layout;
        }
开发者ID:nattress,项目名称:corert,代码行数:56,代码来源:NativeLayoutFieldAlgorithm.cs

示例2: ComputeStaticFieldLayout

        public override ComputedStaticFieldLayout ComputeStaticFieldLayout(DefType type, StaticLayoutKind layoutKind)
        {
            if (!type.IsTemplateUniversal() && (layoutKind == StaticLayoutKind.StaticRegionSizes))
            {
                return ParseStaticRegionSizesFromNativeLayout(type);
            }

            LowLevelList<int> fieldOffsets;
            int[] position = ComputeTypeSizeAndAlignment(type, FieldLoadState.Statics, out fieldOffsets);

            int numStaticFields = 0;
            foreach (NativeLayoutFieldDesc field in type.NativeLayoutFields)
            {
                if (field.IsStatic)
                {
                    numStaticFields++;
                }
            }

            ComputedStaticFieldLayout layout = new ComputedStaticFieldLayout();

            layout.Offsets = new FieldAndOffset[numStaticFields];

            if (numStaticFields > 0)
            {
                layout.GcStatics = new StaticsBlock() { Size = position[(int)NativeFormat.FieldStorage.GCStatic], LargestAlignment = DefType.MaximumAlignmentPossible };
                layout.NonGcStatics = new StaticsBlock() { Size = position[(int)NativeFormat.FieldStorage.NonGCStatic], LargestAlignment = DefType.MaximumAlignmentPossible };
                layout.ThreadStatics = new StaticsBlock() { Size = position[(int)NativeFormat.FieldStorage.TLSStatic], LargestAlignment = DefType.MaximumAlignmentPossible };
            }

            int curStaticField = 0;
            foreach (NativeLayoutFieldDesc field in type.NativeLayoutFields)
            {
                if (field.IsStatic)
                {
                    layout.Offsets[curStaticField] = new FieldAndOffset(field, fieldOffsets[curStaticField]);
                    curStaticField++;
                }
            }

            return layout;
        }
开发者ID:nattress,项目名称:corert,代码行数:42,代码来源:NativeLayoutFieldAlgorithm.cs

示例3: EnsureFieldLayoutLoadedForGenericType

        internal static void EnsureFieldLayoutLoadedForGenericType(DefType type)
        {
            if (type.NativeLayoutFields != null)
                return;

            if (!type.IsTemplateUniversal())
            {
                // We can hit this case where the template of type in question is not a universal canonical type.
                // Example:
                //  BaseType<T> { ... }
                //  DerivedType<T, U> : BaseType<T> { ... }
                // and an instantiation like DerivedType<string, int>. In that case, BaseType<string> will have a non-universal
                // template type, and requires special handling to compute its size and field layout.
                EnsureFieldLayoutLoadedForNonUniversalType(type);
            }
            else
            {
                TypeBuilderState state = type.GetOrCreateTypeBuilderState();
                NativeParser typeInfoParser = state.GetParserForNativeLayoutInfo();
                NativeParser fieldLayoutParser = typeInfoParser.GetParserForBagElementKind(BagElementKind.FieldLayout);
                EnsureFieldLayoutLoadedForUniversalType(type, state.NativeLayoutInfo.LoadContext, fieldLayoutParser);
            }
        }
开发者ID:nattress,项目名称:corert,代码行数:23,代码来源:NativeLayoutFieldAlgorithm.cs


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