The following macro will take a private member declaration and turn it into a public property. It takes into account leading underscores as well as "new" keywords.
Private _pageStats As New PageStats
'PageStats
Public Property PageStats() As PageStats
Get
Return _pageStats
End Get
Set(ByVal Value As PageStats)
_pageStats = Value
End Set
End Property
Sub ConvertFieldToProperty()
Dim document As TextDocument = DTE.ActiveDocument.Object
With document.Selection
'position cursor at beginning of text
.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
'move right of scope (e.g. "Private")
.WordRight()
'check for leading underscore; if exist, delete
.CharRight(True)
If .Text = "_" Then
.Delete()
End If
'cap first part of member string (e.g. "MyMember")
.ChangeCase(vsCaseOptions.vsCaseOptionsUppercase)
'select member without scope (e.g. "myMember as String")
.EndOfLine(True)
'copy selection
Dim memberWithNew As String = .Text
Dim memberWithoutNew As String = memberWithNew.Replace(" New ", " ")
memberWithoutNew = memberWithoutNew.Replace(" new ", " ")
'select scope portion
'create comment header for property block
.Text = "'" & memberWithoutNew
.WordLeft(True, 2)
.NewLine()
'replace old scope with new private scope for member
'and insert lowercase member block
.WordRight(True)
.Text = "Private _" & memberWithNew
.StartOfLine()
.CharRight(True, 2)
.ChangeCase(vsCaseOptions.vsCaseOptionsLowercase)
.EndOfLine()
'create property block
.Text = "Public Property " & memberWithoutNew
.Text = "Return _" & memberWithoutNew
.DeleteLeft()
.WordLeft()
.CharRight()
.LineDown(False, 3)
.Text = memberWithoutNew
.Text = "_"
.Text = "= Value"
'select entire block
.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
.LineUp(True, 10)
'format block
DTE.ExecuteCommand("Edit.FormatSelection")
'create a new line at the end and place cursor on following line
.LineDown()
.LineUp(False, 2)
End With
End Sub
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u
Page rendered at Friday, November 21, 2008 6:12:31 AM (Central Standard Time, UTC-06:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.