Search code examples
c#visual-studiovisual-studio-2010usingresolve

Remove using statements and resolve each reference in Visual Studio 2010 (C#)


I need a way to remove ALL using statements from code and fully qualify the referenced lines of code. Example:

BEFORE:

using System.Windows.Forms;
namespace XYZ
{
    class Temp
    {
        public void IRFunction()
        {
            MessageBox.Show("Hello!");
        }
    }
}

AFTER:

namespace XYZ
{
    class Temp
    {
        public void IRFunction()
        {
            System.Windows.Forms.MessageBox.Show("Hello!");
        }
    }
}

I am assuming that the solution would automatically answer the following question as well: How to enumerate referenced namespaces that qualify for using statements and can be used to resolve references in code.


Solution

  • I'm not sure why you would want to do that, but...

    ReSharper can do that for you.

    Options > Code Editing > C# > Namespace Imports

    Then set the "Use Fully Qualified Names" radio button.

    Once that is set, you can do a "Code Cleanup" on existing code, and it will change your usings to fully qualified names.