Visual Studio sorts usings in wrong order
I've just discovered what seems to be an annoying bug in Visual Studio 2010. It appears that the Sort Usings function is sorting my usings in the wrong order. Have a look at this code:
namespace Test
{
开发者_JAVA技巧using Test.WebPages.Utilities;
using Test.WebPages.WebRef;
using Test.WebPages.ViewModels;
namespace WebPages
{
namespace Utilities { class A { } }
namespace WebRef { class B { } }
namespace ViewModels { class C { } }
}
public class Program
{
public static void Main()
{
var a = new A();
var b = new B();
var c = new C();
}
}
}
Obviously the sort order is wrong. Annoying when you're using StyleCop SA1210.
I don't think that Sort Usings does anything to usings inside of a namespace
Aha, now I have some more insight. I tried this:
using Test.W; // place W here, initially
using Test.U;
using Test.V;
using Test.X;
using Test.Y;
namespace Test
{
namespace U { class A { } }
namespace V { class B { } }
namespace W { class C { } }
namespace X { class D { } }
namespace Y { class E { } }
public class Program
{
public static void Main()
{
new A();
new B();
new C();
new D();
new E();
}
}
}
Sorting the usings above results in:
using Test.U;
using Test.W; // place W here, initially
using Test.V;
using Test.X;
using Test.Y;
which is wrong, of course. However, I then tried this order initially:
using Test.U;
using Test.V;
using Test.X;
using Test.Y;
using Test.W; // place W here, initially
Sorting this resulted in the correct order:
using Test.U;
using Test.V;
using Test.W; // place W here, initially
using Test.X;
using Test.Y;
Very strange.
精彩评论