System.Runtime.InteropServices.StructLayoutAttribute.GetCustomAttribute C# (CSharp) Method

GetCustomAttribute() static private method

static private GetCustomAttribute ( Type type ) : Attribute
type Type
return Attribute
        internal static Attribute GetCustomAttribute(Type 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: ASSERT.UNREACHABLE(); 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: ASSERT.UNREACHABLE(); break;
            }
            type.Module.MetadataImport.GetClassLayout(type.MetadataToken, out pack, out size);

            // 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); 
        }