Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 905 Bytes

MA0008.md

File metadata and controls

32 lines (26 loc) · 905 Bytes

MA0008 - Add StructLayoutAttribute

The rule reports structs where

  • There are at least 2 fields
  • All fields are blittable
  • The struct is not decorated with [StructLayout]
struct A { } // ok
struct A { public int A; } // ok as the struct single blittable type
struct A { public int A; public string B } // ok as the struct contains a not blittable field

struct A { public int A; public int B; } // report diagnostic as both fields are blittable
struct Sample
{
    public int A;
    public int B;
}

// Should be
[StructLayout(LayoutKind.XXX)]
struct Sample
{
    public int A;
    public int B;
}

More information: Optimize struct performances using StructLayout