A quick and dirty VB.NET property generator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard

    A quick and dirty VB.NET property generator

    the previous code assumed that the private variable begins with an
    underscore "_" and there is no assignment. I've fixed it to check for
    these.

    Sub PropertyMacro()
    Dim ClassDeclaratio n As Document = DTE.ActiveDocum ent
    Dim temp As TextWindow =
    CType(ClassDecl aration.ActiveW indow.Object, TextWindow)

    Dim PropDeclaration As String = "public "
    Dim decl As String() = Trim(temp.Selec tion.Text).Spli t(" ")
    Dim memvar As String = decl(2)

    If memvar.Substrin g(memvar.Length - 1, 1) = ";" Then memvar =
    memvar.Substrin g(0, memvar.Length - 1)

    Dim propName As String = memvar
    If propName.Substr ing(0, 1) = "_" Then propName =
    propName.Substr ing(1)

    propName = propName.Substr ing(0, 1).ToUpper() &
    propName.Substr ing(1)
    Dim dataType As String = decl(1)
    PropDeclaration += dataType & " " & propName

    temp.Selection. LineDown()
    temp.Selection. Insert(vbTab & vbTab & PropDeclaration )
    temp.Selection. Insert("{")
    temp.Selection. Insert("get{")
    temp.Selection. Insert("return " & memvar & ";}")
    temp.Selection. Insert("set{")
    temp.Selection. Insert(memvar & " = value;}")
    temp.Selection. Insert("}")
    temp.Selection. NewLine()
    End Sub
Working...