本文整理汇总了C#中Internal.TypeSystem.MetadataType.GetFields方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataType.GetFields方法的具体用法?C# MetadataType.GetFields怎么用?C# MetadataType.GetFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internal.TypeSystem.MetadataType
的用法示例。
在下文中一共展示了MetadataType.GetFields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeSequentialFieldLayout
private static ComputedInstanceFieldLayout ComputeSequentialFieldLayout(MetadataType type, int numInstanceFields)
{
var offsets = new FieldAndOffset[numInstanceFields];
// For types inheriting from another type, field offsets continue on from where they left off
int cumulativeInstanceFieldPos = ComputeBytesUsedInParentType(type);
int largestAlignmentRequirement = 1;
int fieldOrdinal = 0;
int packingSize = ComputePackingSize(type);
foreach (var field in type.GetFields())
{
if (field.IsStatic)
continue;
var fieldSizeAndAlignment = ComputeFieldSizeAndAlignment(field.FieldType, packingSize);
if (fieldSizeAndAlignment.Alignment > largestAlignmentRequirement)
largestAlignmentRequirement = fieldSizeAndAlignment.Alignment;
cumulativeInstanceFieldPos = AlignmentHelper.AlignUp(cumulativeInstanceFieldPos, fieldSizeAndAlignment.Alignment);
offsets[fieldOrdinal] = new FieldAndOffset(field, cumulativeInstanceFieldPos);
cumulativeInstanceFieldPos = checked(cumulativeInstanceFieldPos + fieldSizeAndAlignment.Size);
fieldOrdinal++;
}
if (type.IsValueType)
{
var layoutMetadata = type.GetClassLayout();
cumulativeInstanceFieldPos = Math.Max(cumulativeInstanceFieldPos, layoutMetadata.Size);
}
SizeAndAlignment instanceByteSizeAndAlignment;
var instanceSizeAndAlignment = ComputeInstanceSize(type, cumulativeInstanceFieldPos, largestAlignmentRequirement, out instanceByteSizeAndAlignment);
ComputedInstanceFieldLayout computedLayout = new ComputedInstanceFieldLayout();
computedLayout.FieldAlignment = instanceSizeAndAlignment.Alignment;
computedLayout.FieldSize = instanceSizeAndAlignment.Size;
computedLayout.ByteCountUnaligned = instanceByteSizeAndAlignment.Size;
computedLayout.ByteCountAlignment = instanceByteSizeAndAlignment.Alignment;
computedLayout.Offsets = offsets;
return computedLayout;
}