Hello,
This is my first blog on http://www.geekswithblogs.net and I'm planning on occasionaly publishing things I've learned that I haven't found elsewhere in hopes of helping you out.
I've been annoyed with Silverlight and the Resource (.resx) files we use for translation. Every time I change text in the resource editor, I have to open the .designer.cs file and change the constructor to public. If it is not public, the resource string cannot be bound to in XAML, there is a runtime error. The code generation that happens on save, always changes it to internal. So I created a Macro that I tied to a hot key to make this quicker.
Here is the macro:
Public Module ResourceToPublic
Sub ResourceToPublic()
DTE.ActiveDocument.Selection.PageUp()
DTE.ActiveDocument.Selection.PageUp()
DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.
vsStartOfLineOptionsFirstText)
DTE.ActiveDocument.Selection.LineDown(False, 31)
DTE.ActiveDocument.Selection.CharRight(False, 8)
DTE.ActiveDocument.Selection.WordRight(True)
DTE.ActiveDocument.Selection.Delete()
DTE.ActiveDocument.Selection.Text = "public "
DTE.ActiveDocument.Save()
DTE.ActiveDocument.Selection.PageUp()
DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.
vsStartOfLineOptionsFirstText)
' DTE.ActiveDocument.Close()
End Sub
End Module
This will move the cursor to the top left, then find the internal constructor (which is always in the same location, so I can use linedown and charright), change to public, move the cursor back to the top left and save the document.
To create the Macro in Visual Studio go to Tools -> Macros -> Macros Explorer. Right click on MyMacros and click new module. Paste the code into the correct spot. Then to make it even easier, bind the Macro to a hot key combination. I chose ctrl +, +. To do this, go to Tools -> Options -> Environment -> Keyboard. Type in ResourceToPublic in the textbox and select it. Then in push the keys you want (avoid overriding important ones) and click assign.
You're ready to save your self time and hopefully some grumbling!