Sometimes i think of an easier way to actually convert a private variable into property. As we all know, everybody likes it when someone else does our work. It’s brilliant when computer does it for us on a little command.
- Installation Instructions:
- In Visual Studio.NET Open Macro IDE (hit Alt+F11).
- Open Solution explorer (There is one in Macro explorer as well – hit Ctrl+Alt+L).
- Select any project of you choice from solution explorer and add a new Module called PropertyMaker
- Replace the code with code above and save
- Build Ctrl+Shift+B
- Go Back to Visual Studio.NET
- Go Tools –> Options –> Environment –> Keyboard
- In ‘Show commands containing’ textbox, type ‘ConvertToProperty’, select the method you just added in
- In ‘Press shortcut key(s)’ textbox, enter the command you like. I choose Alt+O, Alt+P (O – Open Source Tools, P – Property Maker)
Ok, This is my code for that macro.
Public Module PropertyMaker
Public Sub ConvertToProperty()
Dim maker As CSharpMaker = New CSharpMaker
Private Class CSharpMaker
Private accesor As String
Private dataType As String
Private variable As String
Private privateVariable As String
Private selection As TextSelection
Private startPt As EditPoint
Private re As Regex
re = New Regex("\b\w+\b")
selection = DTE.ActiveDocument.Selection
Dim selectionText As String = selection.Text
Dim coll As MatchCollection = re.Matches(selectionText)