http://weblogs.asp.net/jan/archive/2003/04/29/6168.aspx faydalı bir VS.NET macrosu...
eklediğiniz
Private _host As String
gibi bir ifadeyi şu şekilde düzenliyor.
Public Property Host() As String
Get
Return _host
End Get
Set(ByVal Value As String)
_host = Value
End Set
End Property
Macro kodu:
Imports EnvDTE
Imports System.Diagnostics
Public Module AslanParcasi
Public Sub ConvertProperties()
DTE.UndoContext.Open("ConvertProperties")
Try
Dim txt As TextSelection
txt = DTE.ActiveDocument.Selection
Dim line, originalCode As String
originalCode = txt.Text
Dim lines() As String
lines = Split(originalCode, vbLf)
Dim variableName, publicName, dataType, propertyProcedure As String
Dim r As System.Text.RegularExpressions.Regex
r = New System.Text.RegularExpressions.Regex( _
"(Dim|Private)\s*(?<varname>\S*)\s*As\s*(?<typename>\S*)", _
System.Text.RegularExpressions.RegexOptions.IgnoreCase _
Or System.Text.RegularExpressions.RegexOptions.IgnoreCase.ExplicitCapture)
For Each line In lines
line = line.Trim
If Not line = "" Then
Dim mtch As System.Text.RegularExpressions.Match
mtch = r.Match(line)
If mtch.Success Then
variableName = mtch.Groups("varname").Value.Trim
dataType = mtch.Groups("typename").Value.Trim
publicName = variableName.Substring(1, 1).ToUpper & variableName.Substring(2)
propertyProcedure = _
String.Format("Public Property {1} As {2}{0}" _
& " Get{0}" _
& " Return {3}{0}" _
& " End Get{0}" _
& " Set(ByVal Value As {2}){0}" _
& " {3} = Value{0}" _
& " End Set{0}" _
& "End Property", vbCrLf, publicName, _
dataType, variableName)
txt.Insert(vbCrLf & propertyProcedure, _
vsInsertFlags.vsInsertFlagsInsertAtEnd)
End If
End If
Next
txt.SmartFormat()
Catch ex As System.Exception
MsgBox("There was an error while constructing Property code: " & _
ex.ToString & ".", MsgBoxStyle.Critical, "ConvertProperties")
End Try
DTE.UndoContext.Close()
End Sub
End Module