Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 sort functions in the editor alphabetically

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() {...}
}
like image 837
Steve Avatar asked Apr 15 '11 10:04

Steve


People also ask

How do I sort alphabetically in Visual Studio?

Select Edit from the menu bar. Select Intellisense > Sort Usings. You can also configure different settings for using directives in Tools > Options > Text Editor > C# > Advanced.

How do you sort a statement in C#?

You can easily organize your using statements. Simply right-click anywhere in the editor to get the context menu, choose Organize Usings, and then Remove, Sort, or Remove And Sort.


1 Answers

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
like image 125
EvilTeach Avatar answered Sep 18 '22 17:09

EvilTeach