Here is macro to generate the property code for
VB.Net:
Sub GeneratePropertyCode()
Dim FieldDetailList As New System.Collections.ArrayList
Dim FieldName, FieldDataType As String
While True
DTE.ActiveDocument.Selection.StartOfLine(vsStartOf LineOptions.vsStartOfLineOptionsFirstText)
DTE.ActiveDocument.Selection.EndOfLine(True)
If Left(DTE.ActiveDocument.Selection.Text, 9) = "Private _" Then
FieldDetailList.Add(DTE.ActiveDocument.Selection.T ext)
DTE.ActiveDocument.Selection.LineDown(False, 1)
Else
Exit While
End If
End While
For i As Integer = 0 To FieldDetailList.Count - 1
FieldName = Mid(FieldDetailList(i).ToString(), 10, InStr(FieldDetailList(i).ToString(), " As") - 10)
FieldDataType = Mid(FieldDetailList(i).ToString(), InStr(FieldDetailList(i).ToString(), "As ") + 3, 50)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "Public Property " & FieldName & " as " & FieldDataType
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "Return _" & FieldName
DTE.ActiveDocument.Selection.LineDown(False, 3)
DTE.ActiveDocument.Selection.Indent(3)
DTE.ActiveDocument.Selection.Text = "Value = _" & FieldName
DTE.ActiveDocument.Selection.LineDown(False, 2)
Next
End Sub
Try out on this class:
Public Class Student
Private _Id As Integer
Private _Name As String
Private _BirthDate As Date
End Class
You need to place the cursor on the line where first private variable declared and then run the macro GeneratePropertyCode. Please note some code is hardcoded in macro, you can modify according to your need.
Cheers,
Pooja Falor