A public static readonly array can still have its elements changed by any code
What it finds
readonly protects the field, not the array: Config.Names[0] = "x" changes the shared array for everyone. An ImmutableArray, a ReadOnlyCollection or a property returning a copy keeps the elements fixed.
From the rule's source, exposed_static_array.rs.
public class Lists{ public static readonly string[] Names = { "a", "b" };tx0 reports: the elements of the public array Names can be changed by any code private static readonly string[] Hidden = { "c" }; public static readonly System.Collections.Generic.IReadOnlyList<string> Safe = new[] { "d" };} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:exposed-static-array" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:exposed-static-array] reason="..."tx0 explain tx0/csharp:exposed-static-array shows the same in the terminal. Found a false positive? Report it.