Skip to main content
A newer version of this page is available. .

Remove Type Qualifier

  • 2 minutes to read

Purpose

This refactoring removes the redundant type qualifier from a type reference (for example, System.Text.StringBuilder) and adds the corresponding namespace reference to the file if it does not exist.

Availability

Available when the cursor is in a fully-qualified reference to a type.

Usage

  1. Place the caret in a fully-qualified type reference.

    NOTE

    The blinking cursor shows the caret's position at which the Refactoring is available.

    namespace CRRDemo {
        class Program {
            static void Main(string[] args) {
                var o = new System.Text.StringBuilder();
            }
        }
    }
    
  2. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  3. Select Remove Type Qualifier menu item.

After execution, the Refactoring removes the namespace from a type reference and ensures the namespace is referenced.

using System.Text;

namespace CRRDemo {
    class Program {
        static void Main(string[] args) {
            var o = new StringBuilder();
        }
    }
}
NOTE

If you need to remove the type qualifier from all fully-qualified type references in the current file, use the Remove Type Qualifier (remove all) Code Actions Menu item.

Blazor Support

You can apply the Remove Type Quallifier refactoring from the code section in a .razor file.

Blazor Support

See Also