A public member exposes List<T>, which ties callers to one implementation and lets them change it freely
What it finds
List<T> in a public signature is a promise to keep using exactly that type, and it offers callers every mutating method. IReadOnlyList<T>, IList<T> or Collection<T> leave room to change the implementation and to control changes. The rule reports public methods of public types that return or take List<T>, and public properties of that type. Overrides are left alone.
From the rule's source, concrete_list_in_public_api.rs.
using System.Collections.Generic; public class Catalog{ public List<string> Names() => new List<string>();tx0 reports: Names exposes List<T> in its signature public IReadOnlyList<string> Titles() => new List<string>(); private List<int> Ids() => new List<int>();} 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:concrete-list-in-public-api" = "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:concrete-list-in-public-api] reason="..."tx0 explain tx0/csharp:concrete-list-in-public-api shows the same in the terminal. Found a false positive? Report it.