
Aggiungere una Property
Obiettivo 1: selezionare un field pubblico di classe, cliccare un bottone sulla Toolbar di VS.NET, indicare se si vuole solo il Get, solo il Set o entrambi e quindi ottenere automaticamente la dichiarazione del Field privato e il codice della Property.
Obiettivo 2: oppure cliccare un bottone sulla Toolbar di VS.NET, indicare il tipo e il nome della Property, indicare se si vuole solo il Get, solo il Set o entrambi e quindi ottenere automaticamente la dichiarazione del Field privato e il codice della Property.
Come?
Passo1/2:  Scarica la macro da qui.
E quindi modifica la Sub CreateProperty() in questo modo:
Const sPREFIX As String = "_"Dim sTypeName As StringDim sMethodName As StringDim sFieldName As StringDim ts As TextSelectionDim sb As New StringBuilder()Dim boolIsOpened As BooleanDim sInit As StringDim words() As StringDim visibility As String 
CheckLanguage()
 Try
	ts = DTE.ActiveDocument.Selection
	If ts.Text = "" Then		Dim nuova As String		nuova = InputBox("Inserisci il tipo della Property: ", "Property Type")
		nuova = nuova + " " + InputBox("Inserisci il nome della Property: ", "Property Name")
		nuova.Trim(" ")
		ts.Insert(nuova, vsInsertFlags.vsInsertFlagsInsertAtStart)
	End If 
	words = ts.Text.Replace(vbTab, " ").Trim(" ").Split(" ")
 
	visibility = words(0).ToLower()
 	If visibility = "public" Or visibility = "protected" Then
		sTypeName = words(1)
		sMethodName = words(2).Replace(";", "")
		If UBound(words) >= 3 Then			sInit = " " + 
String.Join(" ", words, 3, words.GetUpperBound(0) - 2)		Else			sInit = ";"
		End If	Else		visibility = "public"
		sTypeName = words(0)
		sMethodName = words(1).Replace(";", "")
		sInit = ";"
	End If 	Dim bloccoGet As Boolean = True
	Dim bloccoSet As Boolean = True
 	If MsgBox("Solo Get?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "Property Get/Set") = MsgBoxResult.Yes Then
		bloccoSet = 
False	ElseIf MsgBox("Solo Set?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "Property Get/Set") = MsgBoxResult.Yes Then		bloccoGet = 
False	End If 	' casing()
	sFieldName = sPREFIX + sMethodName.Substring(0, 1).ToLower() + sMethodName.Substring(1)
	sMethodName = sMethodName.Substring(0, 1).ToUpper() + sMethodName.Substring(1)
 	' field
	sb.Append("private " + sTypeName + " " + sFieldName + sInit)
	sb.Append(vbCrLf).Append(vbCrLf)
 	' method
	sb.Append(visibility + " " + sTypeName + " " + sMethodName)
	If bloccoGet And bloccoSet Then		sb.Append(vbCrLf)
		sb.Append("{")
		sb.Append(vbCrLf)
	Else		sb.Append(" {")
	End If 	If bloccoGet Then
		' get		sb.Append("get ")
		sb.Append("{")
		sb.Append(" return " + sFieldName + "; ")
		sb.Append("}")
		If Not bloccoSet Then			sb.Append(" ")
		Else			sb.Append(vbCrLf)
		End If	End If 	If bloccoSet Then
		' set		sb.Append("set ")
		sb.Append("{")
		sb.Append(" " + sFieldName + " = value; ")
		sb.Append("}")
		If Not bloccoGet Then			sb.Append(" ")
		Else			sb.Append(vbCrLf)
		End If	End If 
	sb.Append("}").Append(vbCrLf)
 	'Check to see if UndoContext object is already open.
	If DTE.UndoContext.IsOpen = False Then		'Open the UndoContext object to track changes.		Call DTE.UndoContext.Open("CreateProperty " & sMethodName, False)		boolIsOpened = 
True	End If 	' Replace the text and SmartFormat it
	ts.Delete()
	ts.Insert(sb.ToString(), vsInsertFlags.vsInsertFlagsInsertAtStart)
	ts.TopPoint.CreateEditPoint.SmartFormat(ts.BottomPoint)
Catch	Beep()
Finally	'If UndoContext was already open, don't close it.	If boolIsOpened = True Then		'Close the UndoContext object to commit the changes.		Call DTE.UndoContext.Close()	End IfEnd Try
 
Passo 2/2: Aggiungere un button nella Toolbar di VS.NET per richiamare la macro
Seguire le istruzioni qui indicate al punto "Putting a Macro on a Menu or Command Bar".
bye (luKa)