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. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select the Remove Type Qualifier menu item.

After execution, this 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 All Type Qualifiers Code Actions menu item.

Blazor Support

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

Blazor Support

See Also