Macro to Add using System.Linq
- by Aligned
I have Visual Studio 2010 setup to remove and sort settings on save with the Power Commands extensions. This is great, but sometimes it removes the using System.Linq at the top. I also find myself scrolling to the top to add the using when I first add System.Linq. So I wrote a quick macro to do it for me. Sub AddUsingLinq() DTE.ActiveDocument.Selection.StartOfDocument() DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) DTE.ActiveDocument.Selection.Text = "using System.Linq;" DTE.ActiveDocument.Selection.NewLine() DTE.ExecuteCommand("Edit.FormatDocument") DTE.ExecuteCommand("Edit.RemoveAndSort") DTE.ActiveDocument.Save() DTE.ExecuteCommand("View.NavigateBackward") End SubHook this up to a shortcut (tools -> options -> keyboard, I chose ctrl + x, c) and you'll be moving faster than ever.