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 template and supporting variables

Private Cr As String = Environment.NewLine
Private Start As String = "{"
Private Close As String = "}"

Private mask As String = _
	"/// <summary>{3}</summary>" + Cr + _
	"private {0} {2};" + Cr + _
	"/// <summary>{3}</summary>" + Cr + _
	"public {0} {1}" + Cr + "{{" + Cr + _
	"get {{ return {2};  }}" + Cr + _
	"set {{ {2} = value; }}" + Cr + "}}"

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.

Public Sub GeneratePublicProperty()
	Dim PropertyType As String = _
	  InputBox("Property Return type:", "Property Type")

	Dim PropertyName As String = _
	  InputBox("Property Name:", "Property Name")

	Dim FieldName As String = _
	  InputBox("Internal Variable name:", "Field Name")

	Dim Summary As String = InputBox("Summary:", "Summary")

	Dim Code As String = String.Format(mask, PropertyType, PropertyName, FieldName, Summary)

	PasteAlign(Code)

End Sub

Here is the code that outputs it to the screen.

Private Sub PasteAlign(ByVal Code As String)

	' Debug.WriteLine(Code)

	Dim ts As TextSelection = DTE.ActiveWindow.Selection

	ts.Insert(Code.ToString(), vsInsertFlags.vsInsertFlagsInsertAtStart)
	ts.TopPoint.CreateEditPoint.SmartFormat(ts.BottomPoint)

End Sub
Share