Wednesday, February 08, 2006

For the Code Nazis amongst you

A Visual Studio 2005 macro that sorts the using statements.

Sub SortUsingStatements()
Dim selectedText As TextSelection
Dim line As String
Dim out As String
Dim nonSystem As String
Dim systemLines As String
Dim systemOnly As String

selectedText = DTE.ActiveDocument.Selection
Dim lines() As String = Split(selectedText.Text, vbLf)


For Each line In lines
If line.Contains("System;") Then
systemOnly = line + vbLf

ElseIf line.Contains("System") Then
systemLines = systemLines + line + vbLf

nonSystem = nonSystem + line + vbLf
End If
out = systemOnly + systemLines + nonSystem
End Sub

No comments: