CRR0043 - Unused type

  • 2 minutes to read

This analyzer detects types that are not referenced in code. Specify accessibility levels for these types in the CodeRush options dialog:

  • Open the Editor | C# (Visual Basic) | Code Analysis | Unused Code Analysis options page.
  • Specify accessibility levels for unused types. For example, check the internal (Friend) option and uncheck other options to allow the analyzer to detect unused internal types only.

RemoveQualifier

The following example demonstrates how the analyzer detects an unused internal class:

RemoveQualifier

TIP

Use the Highlight unused code in editor check box in the Editor | C# (Visual Basic) | Code Analysis | General option page to enable or disable the highlighting of unused types in the code editor.

To fix this issue, perform one of the following actions in the code:

  • Remove the unused internal class:
public class UsedClass
{
    private class AnotherUnusedClass
    {

    }
}
  • Call the Remove Unused Type refactoring.

  • Use the Remove unused types rule to remove unused internal types in different places at once:

1) Specify options as shown in the screenshot below. This allows CodeRush to apply this cleanup rule when you save a document and when you run code cleanup.

EnableCleanup

2) Run Code Cleanup.

You can use the Remove unused private types rule to remove unused private types.