Domanda

Quando digito il trigger la funzione di commento automatico in Visual Studio (digitando " '' '" o " /// "), la maggior parte dei dettagli dei commenti XML mostrano che mi piace. Tuttavia, in genere aggiungo il tag di cronologia alla documentazione in modo da poter tenere traccia e le modifiche apportate al metodo nel tempo.

Esiste un modo per personalizzare la funzione di commento automatico in modo che aggiunga il tag cronologico e potenzialmente un nome generico - Data - Cambia testo segnaposto?

È stato utile?

Soluzione

Suggerirei di utilizzare GhostDoc . Genera commenti molto intelligenti usando /// in base ai nomi e ai parametri del metodo. Inoltre, è completamente personalizzabile.

Altri suggerimenti

Penso che potresti usare uno strumento come ha detto Dgarcia, ma prova a sceglierne uno che faccia insetad il controllo della versione, Personalmente non sono un grande fan di mantenere la "storia" o traccia del progetto usando i commenti nel codice.

Se ti piace in questo modo potresti creare la tua versione personalizzata dello snippet, questo è più semplice se usi uno strumento come Snippy

Copia questo file al tuo

Documenti \ Visual Studio 2005 \ Snippet di codice [Lingua] \ Snippet di codice \

Fai solo attenzione a cambiare il file se lo userai in VB.NET

Spero che questo aiuto

Proprio come seguito al commento a Olivier. Ecco una copia della macro ora, cerca la sezione '' Do History per vedere dove ho inserito il codice.

    ''// InsertDocComments goes through the current document using the VS Code Model
    ''// to add documentation style comments to each function.
    ''
    Sub InsertDocComments()
        Dim projectItem As ProjectItem
        Dim fileCodeModel As FileCodeModel
        Dim codeElement As CodeElement
        Dim codeElementType As CodeType
        Dim editPoint As EditPoint
        Dim commentStart As String

        projectItem = DTE.ActiveDocument.ProjectItem
        fileCodeModel = projectItem.FileCodeModel
        codeElement = fileCodeModel.CodeElements.Item(1)

        ''// For the sample, don't bother recursively descending all code like
        ''// the OutlineCode sample does. Just get a first CodeType in the
        ''// file.
        If (TypeOf codeElement Is CodeNamespace) Then
            codeElement = codeElement.members.item(1)
        End If
        If (TypeOf codeElement Is CodeType) Then
            codeElementType = CType(codeElement, CodeType)
        Else
            Throw New Exception("Didn't find a type definition as first thing in file or find a namespace as the first thing with a type inside the namespace.")
        End If

        editPoint = codeElementType.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint()

        ''// Make doc comment start.
        commentStart = LineOrientedCommentStart()
        If (commentStart.Length = 2) Then
            commentStart = commentStart & commentStart.Chars(1) & " "
        ElseIf (commentStart.Length = 1) Then
            commentStart = commentStart & commentStart.Chars(0) & commentStart.Chars(0) & " "
        End If

        ''// Make this atomically undo'able.  Use Try...Finally to ensure Undo
        ''// Context is close.
        Try
            DTE.UndoContext.Open("Insert Doc Comments")

            ''// Iterate over code elements emitting doc comments for functions.
            For Each codeElement In codeElementType.Members
                If (codeElement.Kind = vsCMElement.vsCMElementFunction) Then
                    ''// Get Params.
                    Dim parameters As CodeElements
                    Dim codeFunction As CodeFunction
                    Dim codeElement2 As CodeElement
                    Dim codeParameter As CodeParameter

                    codeFunction = codeElement
                    editPoint.MoveToPoint(codeFunction.GetStartPoint(vsCMPart.vsCMPartHeader))
                    ''//editPoint.LineUp()
                    parameters = codeFunction.Parameters

                    ''// Do comment.
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.LineUp()
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "<summary>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "Summary of " & codeElement.Name & ".")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "</summary>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)

                    For Each codeElement2 In parameters
                        codeParameter = codeElement2
                        editPoint.Insert("<param name=" & codeParameter.Name & "></param>")
                        editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                        editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)
                    Next ''//param

                    ''// Do history tag.
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.LineUp()
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "<history>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "Name   MM/DD/YYYY   [Created]")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "</history>")
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
                    editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)

                End If ''//we have a function
            Next ''//code elt member

        Finally
            DTE.UndoContext.Close()
        End Try
    End Sub

Per qualche motivo, dopo un salvataggio, una ricostruzione e un riavvio di Visual Studio, non ottengo il tag di cronologia. Qualcuno può vedere qualcosa qui che mi manca?

vb usa un file xml per caricare i defults. Si tratta di VBXMLDoc.xml e dipende dalla versione in esecuzione sulla posizione del file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top