Skip to content

Commit

Permalink
Improve documentation of MA0008 (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored Nov 20, 2023
1 parent c8cd592 commit bb33336
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/Rules/MA0008.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# MA0008 - Add StructLayoutAttribute

The rule reports `struct`s where
- There are at least 2 fields
- All fields are [blittable](https://learn.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types?WT.mc_id=DT-MVP-5003978)
- The struct is not decorated with `[StructLayout]`

````c#
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
````

````csharp
struct Sample
{
public int A;
public int B;
}


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

Expand Down

0 comments on commit bb33336

Please sign in to comment.