本文整理匯總了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);
}