Here's a macro you can use from VS. I didn't write this but it seems
to work fairly well and you can customize to your liking. You can add
a button to the toolbar and have it execute this macro. To use the
macro, highlight the private declaration of the variable and then run
the macro. It will create the property definitions. Watch for line
breaks.
'BEGIN CODE HERE
Imports EnvDTE
Imports System.Diagnostics
Public Module Module1
Public Sub PropertFromVar()
Dim ts As TextSelection = DTE.ActiveWindow.Selection
Dim m_PropertyList(ts.TextRanges.Count - 2) As String
Dim m_Index As Integer
Dim start As EditPoint = ts.TopPoint.CreateEditPoint()
Dim endpt As TextPoint = ts.BottomPoint
Try
Do While (start.LessThan(endpt))
m_PropertyList(m_Index) =
start.GetText(start.LineLength).Trim.Replace("New", "").Replace("()",
"")
start.LineDown()
start.StartOfLine()
m_Index += 1
Loop
Catch ex As System.Exception
Debug.WriteLine(ex)
Finally
'If an error occured, then need to make sure that the undo
context is cleaned up.
'Otherwise, the editor can be left in a perpetual undo
context
End Try
Dim cnt As Integer = m_Index
For m_Index = 0 To m_PropertyList.GetUpperBound(0)
InsertProperty(m_PropertyList(m_Index))
Next
DTE.ExecuteCommand("Edit.FormatDocument")
End Sub
Private Sub InsertProperty(ByVal prop As String)
Dim pmember As String = prop.Substring(prop.IndexOf(" "c)).Trim
Dim ptype As String = pmember.Substring(pmember.IndexOf("As"))
Dim pname As String = pmember.Substring(2)
pname = pname.Substring(0, pname.IndexOf("As")).Trim
pmember = pmember.Substring(0, pmember.Length -
ptype.Length).Trim
Dim ts As TextSelection = DTE.ActiveWindow.Selection
ts.MoveToPoint(ts.ActivePoint.CodeElement(vsCMElement.vsCMElementClass).GetEndPoint(vsCMPart.vsCMPartWhole))
ts.LineUp()
ts.EndOfLine()
ts.NewLine()
ts.NewLine()
ts.Insert("Public Property " & pname & "() " & ptype)
ts.NewLine()
ts.Insert("Return " & pmember)
ts.LineDown(count:=2)
ts.StartOfLine()
ts.Delete(ts.ActivePoint.LineLength)
ts.Insert(Chr(9))
ts.Insert("Set (byval Value " & ptype & ")")
ts.NewLine()
ts.Insert(pmember & "= Value")
ts.LineDown()
ts.Delete()
End Sub
End Module
'CODE ENDS HERE