Visual Studio 2010 sort functions in the editor al

2019-06-20 15:27发布

does anyone know a way to sort the functions of a class in the editor (c#) alphabetically? i.e.

public class Foo
{
    public void B() {...}  
    public void D() {...}
    public void A() {...}
}

After sorting the class should look like

public class Foo
{
    public void A() {...}
    public void B() {...}  
    public void D() {...}
}

4条回答
欢心
2楼-- · 2019-06-20 15:37

Create this macro.

Select the text to sort, and run the macro.

Sub SortSelectedText()
    Dim Selection As TextSelection = DTE.ActiveDocument.Selection
    Dim Lines() As String = Selection.Text.Replace(Environment.NewLine, Chr(13)).Split(Chr(13))
    Array.Sort(Lines)
    DTE.UndoContext.Open("Sort Lines")
    Selection.Delete()
    Selection.Insert(String.Join(Environment.NewLine, Lines))
    DTE.UndoContext.Close()

End Sub
查看更多
姐就是有狂的资本
3楼-- · 2019-06-20 15:39

Did you try codemaid? Is open source. There are others like ReSharper that are really good too.

查看更多
三岁会撩人
4楼-- · 2019-06-20 15:44
姐就是有狂的资本
5楼-- · 2019-06-20 15:47

You can check the Open Source project NArrange, it can sort the using statements as well as all the members and classes in your files, and much more.

http://www.narrange.net/

The latest version is from 2009-12-05, so the project may not evolve any more, but it looks stable enough already.

查看更多
登录 后发表回答