unused-private-member
What it does
Section titled “What it does”Reports a private field, method, property or event that no file of the project uses (needs analysis: deep). Members with attributes, overrides, interface implementations, extern and partial methods are not reported, and neither are the private methods named in reflection_methods of a type derived from one of reflection_base_types (a framework calls them by reflection; the csharp/unity preset lists Unity’s).
Why it matters
Section titled “Why it matters”A private member that nothing uses is dead code that readers have to understand, tests and refactorings have to keep, and the compiler has to compile.
To fix, delete it.
Configuration
Section titled “Configuration”csharp: lint: rules: unused-private-member: level: warn # off, warn (default), error options: reflection_base_types: [] reflection_methods: []| Option | Type | Default | Description |
|---|---|---|---|
reflection_base_types |
list | [] |
Names of base classes whose derived types are called by a framework through reflection (with reflection_methods). A base is matched by its simple name anywhere up the inheritance chain, also when the project does not load its assembly. |
reflection_methods |
list | [] |
Names of private methods that count as used in a type derived from one of reflection_base_types. |
Enabled by the presets: csharp/roslynator, csharp/unity.
Suppress one line with sudsy-disable-next-line unused-private-member in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| Roslynator | RCS1213 |
full |