I created this before the code snippit region came along. This macro will work with VS2003 and VS2005. Simply highlight the code you want and a dialog box will come up asking for the name. Note depending on the location the #region and #endregion will be at those positions.
Sub RegionIt()
Dim sWhat AsString
Â
sWhat = InputBox("Region Name")
Â
If (sWhat <> "") Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection()
Dim start As EditPoint = selection.TopPoint.CreateEditPoint()
Dim endpt As EditPoint = selection.BottomPoint.CreateEditPoint()
DTE.UndoContext.Open("Comment Region")
Try
start.Insert("#region " & sWhat & Chr(13))
endpt.Insert(Chr(13) & "#endregion")
Â
Finally
'If an error occured, then need to make sure that the undo
'context is cleaned up. Otherwise, the editor can be left
Before the intellisense operation prop came about, I had a need to do something similar but to add comments above the property and variable. The below macro, which works in 2005 and 2003 versions of Visual Studio allows one to create a property with comments. The trick is to create a mask/template and fill it with the specifics of what was queried from the user.
Here is the function which should be excecuted to begin the process. Note it simply queries the user for the information, loads the mask and sends it to be outputted.
PublicSub GeneratePublicProperty()
Dim PropertyType AsString = _
InputBox("Property Return type:", "Property Type")
Dim PropertyName AsString = _
InputBox("Property Name:", "Property Name")
Dim FieldName AsString = _
InputBox("Internal Variable name:", "Field Name")
Dim Summary AsString = InputBox("Summary:", "Summary")
Dim Code AsString = String.Format(mask, PropertyType, PropertyName, FieldName, Summary)
PasteAlign(Code)
EndSub