Documenting has never been so easy

Helixoft Blog

Peter Macej - lead developer of VSdocman - talks about Visual Studio tips and automation

Visual Studio 2002 and 2003 contains many sophisticated tools but it misses one of the most important - new procedure/property builder. MZ Tools add-in makes a great job here.

If you only need to create new property, I'll show you a simple macro which will help you. It will ask you for property name and type and then it will place property definition at current cursor position.

Button for Inserting Property

Insert Property Dialog

My example creates following VB .NET property but the macro can be easily modified to generate property for other language as well, e.g. C#:

    Private m_myProperty As String
    '''<summary></summary>
    Public Property myProperty() As String
        Get
            Return m_myProperty
        End Get
        Set(ByVal Value As String)
            m_myProperty = Value
        End Set
    End Property

Here is the macro:

'''<summary>
'''This macro inserts complete property definition
'''including private field.
'''</summary>
Sub InsertProperty()
    DTE.UndoContext.Open("InsertProperty")
    Try
        Dim txt As TextSelection
        txt = DTE.ActiveDocument.Selection

        Dim line As String = InputBox("Name Type", "New Property")
        Dim lines() As String
        lines = Split(line, " ")

        Dim variableName, publicName, dataType, propertyProcedure As String
        publicName = lines(0)
        dataType = lines(1)
        variableName = "m_" & publicName

        propertyProcedure = _
            String.Format( _
                "Private {3} As {2}{0}" _
                & "'''<summary></summary>{0}" _
                & "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(propertyProcedure, _
            vsInsertFlags.vsInsertFlagsInsertAtEnd)
        txt.SmartFormat()
    Catch ex As System.Exception
        'MsgBox("There was an error while constructing Property code: " & _
        '    ex.ToString & ".", MsgBoxStyle.Critical, "New Property")
    End Try
    DTE.UndoContext.Close()
End Sub

See how to create and run macro if you don't know how. You can of course create a toolbar or menu button or assign keyboard shortcut to it.

 

 

Start generating your .NET documentation now!

DOWNLOAD

Free, fully functional trial

Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Quantcast
Accept
Decline