Skip to main content

Remove Type Qualifier

Removes a type qualifier (namespaces) from a type reference and ensures the proper namespace reference is added to the file if needed.

#Availability

Available from the context menu or via shortcuts:

  • when the edit cursor or caret is on a type reference that contains namespace information.

#Notes

There is also a Remove Type Qualifier (replace all) variant of this refactoring, that removes all type qualifiers in a file that match the type qualifier at the caret.

#Example

using System;

namespace MyNamespace
{
    class TestClass
    {
        public TestClass()
        {
            bmpVar = new System.Drawing.Bitmap("BitmapImage.bmp");
        }
        private System.Drawing.Bitmap bmpVar;
    }
}
Imports System

Namespace MyNamespace
    Class TestClass
        Public Sub New(ByVal system As Object)
            bmpVar = New System.Drawing.Bitmap("BitmapImage.bmp")
        End Sub
        Private bmpVar As System.Drawing.Bitmap
    End Class
End Namespace

Result:

using System;
using System.Drawing;

namespace MyNamespace
{
    class TestClass
    {
        public TestClass()
        {
            bmpVar = new Bitmap("BitmapImage.bmp");
        }
        private System.Drawing.Bitmap bmpVar;
    }
}
Imports System
Imports System.Drawing

Namespace MyNamespace
    Class TestClass
        Public Sub New(ByVal system As Object)
            bmpVar = New Bitmap("BitmapImage.bmp")
        End Sub
        Private bmpVar As System.Drawing.Bitmap
    End Class
End Namespace

#Screenshot

rsRemoveTypeQualifierCSharp

See Also