A public property of a collection type has a public setter, so callers can replace the whole collection
What it finds
A collection property is usually changed through the collection: Items.Add(x). A public setter also lets callers swap in another collection, or null, behind the owner's back. A getter-only property, initialized once, keeps the collection under the owner's control. init accessors and data transfer types marked as records are left alone.
From the rule's source, settable_collection_property.rs.
using System.Collections.Generic; public class Order{ public List<string> Lines { get; set; }tx0 reports: the collection property Lines has a public setter public List<string> Tags { get; } = new List<string>(); public List<int> Ids { get; private set; }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:settable-collection-property" = "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:settable-collection-property] reason="..."tx0 explain tx0/csharp:settable-collection-property shows the same in the terminal. Found a false positive? Report it.