Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SA1214 (Readonly fields should appear before non-readonly fields) should not apply to fields when [StructLayout(LayoutKind.Sequential)] is in use. #3819

Open
Kevin-Seiden opened this issue Mar 15, 2024 · 0 comments

Comments

@Kevin-Seiden
Copy link

Consider the following struct:

[StructLayout(LayoutKind.Sequential)]
public struct MyStruct
{
  private int myInt;

  [MarshalAs(UnmanagedType.LPStr)]
  private readonly string myString; // Produces SA1214

  // Accessor properties here
}

Since the struct is adorned with LayoutKind.Sequential, this struct is likely being used in marshaling to unmanaged memory and the order of the fields is imperative to the functionality of the code. I would expect StyleCop Analysers to not recomend SA1214 (or any field ordering rules) in this case.

@sharwell sharwell changed the title SA1214 should not apply to fields when [StructLayout(LayoutKind.Sequential)] is in use. SA1214 (Readonly fields should appear before non-readonly fields) should not apply to fields when [StructLayout(LayoutKind.Sequential)] is in use. Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant