Posted in General

Convert to Property

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:

  1. In Visual Studio.NET Open Macro IDE (hit Alt+F11).
  2. Open Solution explorer (There is one in Macro explorer as well – hit Ctrl+Alt+L).
  3. Select any project of you choice from solution explorer and add a new Module called PropertyMaker
  4. Replace the code with code above and save
  5. Build Ctrl+Shift+B
  6. Go Back to Visual Studio.NET
  7. Go Tools –> Options –> Environment –> Keyboard
  8. In ‘Show commands containing’ textbox, type ‘ConvertToProperty’, select the method you just added in
  9. 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.

Imports EnvDTE
Imports System.Diagnostics
Imports System.Text.RegularExpressions
Imports System.Windows.Forms

Public Module PropertyMaker

Public Sub ConvertToProperty()

Dim maker As CSharpMaker = New CSharpMaker
maker.FormatProperty()

End Sub

'C# Class
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

Sub Init()
re = New Regex("\b\w+\b")
selection = DTE.ActiveDocument.Selection
selection.SelectLine()
Dim selectionText As String = selection.Text

Dim coll As MatchCollection = re.Matches(selectionText)
If coll.Count

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s