This rule raises an issue when a private/internal type or member is never referenced in the code.
A type or member that is never called is dead code, and should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.
This rule detects type or members that are never referenced from inside a translation unit, and cannot be referenced from the outside.
This rule doesn’t raise issues on:
Main method of the application void methods with two parameters when the second parameter type derives from EventArgs DynamicallyAccessedMembersAttribute.
public class Foo
{
private void UnusedPrivateMethod(){...} // Noncompliant, this private method is unused and can be removed.
private class UnusedClass {...} // Noncompliant, unused private class that can be removed.
}
public class Foo
{
public Foo()
{
UsedPrivateMethod();
}
private void UsedPrivateMethod()
{
var c = new UsedClass();
}
private class UsedClass {...}
}