Today I discovered a nice little tool for Visual studio called NArrange. This is what it does according to their website.

* Reduces the amount of time developers spend arranging members within code files. With NArrange, you don’t need to worry about where you place a new member definition in a class… just type away and run NArrange prior to compilation. After formatting, the new member will be automatically moved to the appropriate location in the source file.
* Helps enforce coding style standards
* When used as part of check-in procedures, NArrange can help reduce source code repository conflicts.
* NArrange can automatically group similar code members into predefined region blocks, if supported by the language (C# and VB.Net).
* Reduces the amount of time spent searching for specific members in a code file. Through standard arrangement of source code files, every member of the team will know exactly where in a file to look for private fields, constructors, etc.
* Flexibility – NArrange allows you to configure how members are organized (grouping, sorting, regions, etc.)
* Sort Usings

Sounds promising since I already organise my code that way. I find it makes it easier to find things in my code. Of course, my source files are never very big (if a class file has more then a hundred lines of code in it we can call it big and I don’t have many of those, apart from the designer generated files of course).

So lets get started and set it up. First we download the msi file from the site and do the wizard thing.

Then we set it up in external tools.

Go to Tools -> Extern tools… click Add and fill in the arguments and initial directory and the command. like in the image.

The tool I created here is to do an NArrange on a single source file with a backup of the original (not sure I really need that since I have source control but better safe than finding out you’re a father at the age of 60)

So now we can try this out by choosing a source file and then clicking on Tools -> NArrange.

Of course this works but it is a drag I would rather right-click on a file and do NArrange. No problem you can set this up.

Go to View -> Toolbars -> Customize…, check Context menus and see an extra toolbar appear (magic). Now go to Tools -> NArrange (most likely this will be called External Command 4 but you can change that by right-clicking on it. And drag it while holding down the ctrl-key to the Project and Solution Context Menus -> Item

Then click close on the customize dialog box.

Now you can click on a file and have an NArrange option to click on.

With this as the result in the Output window.

So now I can go in seconds from this.

vb.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Namespace Raman.Parameters
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    <CLSCompliant(True)> _
    Public Class SavitskySmoothParameter
 
#Region " Private members "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private _DegreeOfSmoothing As DegreeOfSmoothingEnum
#End Region
 
#Region " Constructors "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="DegreeOfSmoothing"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal DegreeOfSmoothing As DegreeOfSmoothingEnum)
            _DegreeOfSmoothing = DegreeOfSmoothing
        End Sub
#End Region
 
#Region " Enums "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Enum DegreeOfSmoothingEnum
            DegreeOfSmoothing1 = 5
            DegreeOfSmoothing2 = 9
            DegreeOfSmoothing3 = 13
            DegreeOfSmoothing4 = 19
            DegreeOfSmoothing5 = 25
        End Enum
#End Region
 
#Region " Public properties "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property DegreeOfSmoothing() As DegreeOfSmoothingEnum
            Get
                Return _DegreeOfSmoothing
            End Get
        End Property
#End Region
 
    End Class
End Namespace
Namespace Raman.Parameters
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    <CLSCompliant(True)> _
    Public Class SavitskySmoothParameter

#Region " Private members "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private _DegreeOfSmoothing As DegreeOfSmoothingEnum
#End Region

#Region " Constructors "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="DegreeOfSmoothing"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal DegreeOfSmoothing As DegreeOfSmoothingEnum)
            _DegreeOfSmoothing = DegreeOfSmoothing
        End Sub
#End Region

#Region " Enums "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Enum DegreeOfSmoothingEnum
            DegreeOfSmoothing1 = 5
            DegreeOfSmoothing2 = 9
            DegreeOfSmoothing3 = 13
            DegreeOfSmoothing4 = 19
            DegreeOfSmoothing5 = 25
        End Enum
#End Region

#Region " Public properties "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property DegreeOfSmoothing() As DegreeOfSmoothingEnum
            Get
                Return _DegreeOfSmoothing
            End Get
        End Property
#End Region

    End Class
End Namespace

to this

vb.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Namespace Raman.Parameters
 
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    <CLSCompliant(True)> _
    Public Class SavitskySmoothParameter
 
        #Region "Fields"
 
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private _DegreeOfSmoothing As DegreeOfSmoothingEnum
 
        #End Region 'Fields
 
        #Region "Constructors"
 
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="DegreeOfSmoothing"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal DegreeOfSmoothing As DegreeOfSmoothingEnum)
            _DegreeOfSmoothing = DegreeOfSmoothing
        End Sub
 
        #End Region 'Constructors
 
        #Region "Enumerations"
 
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Enum DegreeOfSmoothingEnum
            DegreeOfSmoothing1 = 5
            DegreeOfSmoothing2 = 9
            DegreeOfSmoothing3 = 13
            DegreeOfSmoothing4 = 19
            DegreeOfSmoothing5 = 25
        End Enum
 
        #End Region 'Enumerations
 
        #Region "Properties"
 
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property DegreeOfSmoothing() As DegreeOfSmoothingEnum
            Get
                Return _DegreeOfSmoothing
            End Get
        End Property
 
        #End Region 'Properties
 
    End Class
 
End Namespace
Namespace Raman.Parameters

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    <CLSCompliant(True)> _
    Public Class SavitskySmoothParameter

        #Region "Fields"

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private _DegreeOfSmoothing As DegreeOfSmoothingEnum

        #End Region 'Fields

        #Region "Constructors"

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="DegreeOfSmoothing"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal DegreeOfSmoothing As DegreeOfSmoothingEnum)
            _DegreeOfSmoothing = DegreeOfSmoothing
        End Sub

        #End Region 'Constructors

        #Region "Enumerations"

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Enum DegreeOfSmoothingEnum
            DegreeOfSmoothing1 = 5
            DegreeOfSmoothing2 = 9
            DegreeOfSmoothing3 = 13
            DegreeOfSmoothing4 = 19
            DegreeOfSmoothing5 = 25
        End Enum

        #End Region 'Enumerations

        #Region "Properties"

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property DegreeOfSmoothing() As DegreeOfSmoothingEnum
            Get
                Return _DegreeOfSmoothing
            End Get
        End Property

        #End Region 'Properties

    End Class

End Namespace

Pretty cool, I think, and something useful for me. Probably not for everyone.

I can now make one for doing complete projects and even solutions.