Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.



Programming and Learning from SD
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 Sub

Hook this up to a shortcut (tools -> options -> keyboard, I chose ctrl + shift + x, c) and you'll be moving faster than ever. 

NOTE: I now use ReSharper and wouldn't want to be without it.
Posted on Tuesday, June 5, 2012 1:18 PM Productivity | Back to top


Comments on this post: Macro to Add using System.Linq

# re: Macro to Add using System.Linq
Requesting Gravatar...
That is a handy little macro. This can easily be extended to add other things that you commonly need to add.

Thanks for sharing.

If you have Resharper, it can be setup to this automatically for any namespace as you use new ones. But it does come with more over head than a simple macro.
Left by Nick Harrison on Jun 06, 2012 9:29 AM

# re: Macro to Add using System.Linq
Requesting Gravatar...
Thanks for the comment! I've used the ReSharper trial version and really liked it. I hope to purchase it sometime soon and I'll use your suggestion.
Left by Kevin on Jun 06, 2012 9:30 AM

Your comment:
 (will show your gravatar)


Copyright © Aligned | Powered by: GeeksWithBlogs.net