You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
[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.
The text was updated successfully, but these errors were encountered:
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
Consider the following struct:
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.
The text was updated successfully, but these errors were encountered: