代码之家  ›  专栏  ›  技术社区  ›  Dillie-O

如何在Visual Studio中自定义自动注释文本?

  •  9
  • Dillie-O  · 技术社区  · 16 年前

    我有没有办法自定义自动注释功能,以便添加历史标记,以及一些通用的名称-日期-更改占位符文本?

    4 回复  |  直到 14 年前
        1
  •  11
  •   DavGarcia    16 年前

    我建议使用 GhostDoc

        2
  •  3
  •   Rulas    16 年前

    如果您喜欢这种方式,您可以创建自己的自定义版本的代码段,如果您使用类似 Snippy

    Copy this file 给你

    My Documents\Visual Studio 2005\Code Snippets[语言]\My Code Snippets\

    如果要在VB.NET中使用,请小心更改该文件

    希望这有帮助

        3
  •  1
  •   Joel Coehoorn    15 年前

    正如对奥利弗评论的后续行动一样。这是宏的副本,请查找“”Do History部分以查看我在何处插入了代码。

        ''// 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
    

    出于某种原因,在保存、重建和重新启动VisualStudio之后,我没有得到历史记录标签。有人能看到我丢失的东西吗?

        4
  •  1
  •   David    13 年前

    推荐文章