本文整理汇总了C#中System.RuntimeType.GetPacking方法的典型用法代码示例。如果您正苦于以下问题:C# RuntimeType.GetPacking方法的具体用法?C# RuntimeType.GetPacking怎么用?C# RuntimeType.GetPacking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.RuntimeType
的用法示例。
在下文中一共展示了RuntimeType.GetPacking方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCustomAttribute
[System.Security.SecurityCritical] // auto-generated
internal static StructLayoutAttribute GetCustomAttribute(RuntimeType type)
{
if (!IsDefined(type))
return null;
int pack = 0, size = 0;
LayoutKind layoutKind = LayoutKind.Auto;
switch (type.Attributes & TypeAttributes.LayoutMask)
{
case TypeAttributes.ExplicitLayout: layoutKind = LayoutKind.Explicit; break;
case TypeAttributes.AutoLayout: layoutKind = LayoutKind.Auto; break;
case TypeAttributes.SequentialLayout: layoutKind = LayoutKind.Sequential; break;
default: Contract.Assume(false); break;
}
CharSet charSet = CharSet.None;
switch (type.Attributes & TypeAttributes.StringFormatMask)
{
case TypeAttributes.AnsiClass: charSet = CharSet.Ansi; break;
case TypeAttributes.AutoClass: charSet = CharSet.Auto; break;
case TypeAttributes.UnicodeClass: charSet = CharSet.Unicode; break;
default: Contract.Assume(false); break;
}
#if MONO
type.GetPacking (out pack, out size);
#else
type.GetRuntimeModule().MetadataImport.GetClassLayout(type.MetadataToken, out pack, out size);
#endif
// Metadata parameter checking should not have allowed 0 for packing size.
// The runtime later converts a packing size of 0 to 8 so do the same here
// because it's more useful from a user perspective.
if (pack == 0)
pack = DEFAULT_PACKING_SIZE;
return new StructLayoutAttribute(layoutKind, pack, size, charSet);
}