Skip to main content

CRR0043 - Unused type

  • 2 minutes to read

This analyzer detects types (for example, classes, records, and record structs) that are not referenced in code. Specify accessibility levels for these types in the CodeRush options dialog:

  1. Open the Editor | C# (Visual Basic) | Code Analysis | Unused Code Analysis options page.
  2. 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:

  1. Remove the unused internal class:

    public class UsedClass
    {
        private class AnotherUnusedClass
        {
    
        }
    }
    
  2. Call the Remove Unused Type refactoring.

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

  4. 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

  5. Run Code Cleanup.

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