A private field is assigned only in its declaration or in constructors and could be readonly

tx0/csharp:field-could-be-readonlyallwarningstyle/conventionsdepth faststyle

What it finds

readonly documents and enforces that a field keeps the value it got when the object was built, which makes the class easier to reason about. The rule reports private fields of classes that nothing outside the constructors assigns, increments or passes by ref. Fields of partial classes and structs, and fields with attributes, are left alone.

From the rule's source, field_could_be_readonly.rs.

Turn it on, off or suppress it

The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:field-could-be-readonly" = "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:field-could-be-readonly] reason="..."

tx0 explain tx0/csharp:field-could-be-readonly shows the same in the terminal. Found a false positive? Report it.