找了前同事要的CodeReview用的命令,在此表示感激啊,以下是原版本的,由于环境不同是使用不了的。代码中还有前公司前辈的签名

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.IO
Imports System.Diagnostics
Imports EnvDTE.Constants
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Threading

Public Module CodeReview
    Public Class CodeReviewRecord
        ' Const csUser = "ZDXIE"
        Public sMethod, sProblem, sSuggest, sModifyTime As String
        Public nLine As Long
        Dim sFileName As String
        Friend Function Init()
            Const passedString = "06.Development"
            Dim sRec As String
            Dim selection As EnvDTE.TextSelection
            Dim startPoint As EnvDTE.EditPoint
            Dim StrArray() As String
            'Get record file name
            sFileName = DTE.ActiveDocument.FullName
            StrArray = Split(sFileName, passedString)
            If StrArray.Length < 2 Then
                MsgBox("the file which your are editting is not controlled by Starteam, record can not write to file.1")
                Return False
            End If
            sFileName = StrArray(0)
            Dim Dirs() As String
            Dirs = Split(sFileName, "\")
            If Dirs.Length < 3 Then
                MsgBox("the file which your are editting is not controlled by Starteam, record can not write to file.2")
                Return False
            End If
            Dim DateStr As String
            DateStr = Format(Now(), "yyyyMMdd")
            Dim proj As String
            proj = Dirs(Dirs.Length - 2)
            sFileName = sFileName + passedString + "\CodeReview\代码检查记录_" + DateStr + "_" + proj + ".txt"
            selection = DTE.ActiveDocument.Selection()
            startPoint = selection.TopPoint.CreateEditPoint()
            nLine = startPoint.Line
            'sMethod = GetFunctionName()
            sModifyTime = System.DateTime.Now.AddDays(1).ToString("yyyyMMdd")
            Return True
        End Function
        Public Sub GenRecord(ByRef sRec As String)
            sRec = vbCrLf + "[时间]:  " + System.DateTime.Now.ToString() + vbCrLf
            sRec = sRec + "[组件]:  " + DTE.ActiveWindow.Project.Name + vbCrLf
            sRec = sRec + "[文件]:  " + DTE.ActiveDocument.FullName + vbCrLf
            sRec = sRec + "[行数]:  " + nLine.ToString() + vbCrLf
            sRec = sRec + "[方法]:  " + sMethod + vbCrLf
            sRec = sRec + "[问题]:  " + sProblem + vbCrLf
            sRec = sRec + "[建议]:  " + sSuggest + vbCrLf
            sRec = sRec + "--------------------" + vbCrLf
            sRec = sRec + "[计划修改时间]:  " + sModifyTime + vbCrLf
            sRec = sRec + "[实际修改时间]:  " + vbCrLf
            sRec = sRec + "[修改结果说明]:  " + vbCrLf
            sRec = sRec + "[验证情况]:  " + vbCrLf
            sRec = sRec + "[验证人]:  " + vbCrLf
            sRec = sRec + "______________________________________________________________________"
        End Sub
        Public Sub Write(ByRef sRec As String)
            Dim file As System.IO.StreamWriter
            file = My.Computer.FileSystem.OpenTextFileWriter(sFileName, True)
            file.WriteLine(sRec)
            file.Close()
        End Sub
    End Class
    Public Class CodeReviewForm
        Inherits System.Windows.Forms.Form
        Private tRec As CodeReviewRecord
        Public WithEvents FuncName As System.Windows.Forms.RichTextBox
        Public WithEvents Problem As System.Windows.Forms.RichTextBox
        Public WithEvents Suggest As System.Windows.Forms.RichTextBox
        Public WithEvents ModifyTime As System.Windows.Forms.RichTextBox
        Friend text1, text2, text3, text4 As System.Windows.Forms.Label
        Friend WithEvents btnSure As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        Public Function Init()
            Return tRec.Init()
        End Function
        Public Sub New()
            MyBase.New()
            tRec = New CodeReviewRecord
            Width = 600
            Height = 520
            SuspendLayout()
            text1 = New System.Windows.Forms.Label
            text1.Location = New System.Drawing.Point(5, 5)
            text1.Name = "lblFuncName"
            text1.Width = 170
            text1.TabIndex = 0
            text1.ForeColor = Color.Blue
            text1.Text = "方法名" ' "function name"
            FuncName = New System.Windows.Forms.RichTextBox
            FuncName.Location = New System.Drawing.Point(5, 25)
            FuncName.Name = "txtFuncName"
            FuncName.Width = 580
            FuncName.Height = 40
            FuncName.TabIndex = 10
            FuncName.Text = GetFunctionName()  'tRec.sMethod 
            text2 = New System.Windows.Forms.Label
            text2.Location = New System.Drawing.Point(5, 75)
            text2.Name = "lblProblem"
            text2.Width = 170
            text2.TabIndex = 0
            text2.ForeColor = Color.Blue
            text2.Text = "问题描述" '"problem description"
            Dim selection As EnvDTE.TextSelection
            selection = DTE.ActiveDocument.Selection()
            Problem = New System.Windows.Forms.RichTextBox
            Problem.Location = New System.Drawing.Point(5, 95)
            Problem.Name = "txtProblem"
            Problem.Width = 580
            Problem.Height = 160
            Problem.TabIndex = 20
            Problem.Text = selection.Text ' tRec.sProblem
            text3 = New System.Windows.Forms.Label
            text3.Location = New System.Drawing.Point(5, 265) ' 165)
            text3.Name = "lblSuggest"
            text3.Width = 170
            text3.TabIndex = 0
            text3.ForeColor = Color.Blue
            text3.Text = "修改建议" ' "fix suggestion"
            Suggest = New System.Windows.Forms.RichTextBox
            Suggest.Location = New System.Drawing.Point(5, 285) '185)
            Suggest.Name = "txtSuggest"
            Suggest.Width = 580
            Suggest.Height = 80
            Suggest.TabIndex = 30
            Suggest.Text = tRec.sSuggest
            text4 = New System.Windows.Forms.Label
            text4.Location = New System.Drawing.Point(5, 375) ' 165)
            text4.Name = "lblModifyTime"
            text4.Width = 170
            text4.TabIndex = 0
            text4.ForeColor = Color.Blue
            text4.Text = "修改时间" ' "fix suggestion"
            ModifyTime = New System.Windows.Forms.RichTextBox
            ModifyTime.Location = New System.Drawing.Point(5, 395) '185)
            ModifyTime.Name = "txtModifyTime"
            ModifyTime.Width = 580
            ModifyTime.Height = 40
            ModifyTime.TabIndex = 40
            ModifyTime.Text = System.DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") 'tRec.sModifyTime
            btnSure = New System.Windows.Forms.Button
            btnSure.Location = New System.Drawing.Point(200, 450) '250)
            btnSure.Name = "btnSure"
            btnSure.Width = 70
            btnSure.TabIndex = 50
            btnSure.Text = "确 定"  '"OK(&O)"
            btnCancel = New System.Windows.Forms.Button
            btnCancel.Location = New System.Drawing.Point(320, 450) ' 250)
            btnCancel.Name = "btnCancel"
            btnCancel.Width = 70
            btnCancel.TabIndex = 60
            btnCancel.Text = "取 消" ' "Cancel(&C)"
            Controls.Add(FuncName)
            Controls.Add(Problem)
            Controls.Add(Suggest)
            Controls.Add(ModifyTime)
            Controls.Add(text1)
            Controls.Add(text2)
            Controls.Add(text3)
            Controls.Add(text4)
            Controls.Add(btnSure)
            Controls.Add(btnCancel)
            AcceptButton = btnSure
            CancelButton = btnCancel
            AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly
            StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
            Name = "Code Review Form"
            Text = "Add CodeReview record"
            ResumeLayout(False)
            TopLevel = True
        End Sub
        Private Sub Sure_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSure.Click
            tRec.sMethod = FuncName.Text.Trim()
            tRec.sProblem = Problem.Text.Trim()
            tRec.sSuggest = Suggest.Text.Trim()
            tRec.sModifyTime = ModifyTime.Text.Trim()
            Dim s As String
            tRec.GenRecord(s)
            tRec.Write(s)
            Close()
        End Sub
        Private Sub Cancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Close()
        End Sub
    End Class
    Public Sub AddCodeReviewRecord()
        Dim sf As New CodeReviewForm
        If (sf.Init()) Then
            sf.BringToFront()
            sf.ShowDialog()
            sf.Activate()
            sf.Focus()
        End If
    End Sub
    Function YYStripTabs(ByVal MyStr)
        Do While InStr(MyStr, vbTab) <> 0
            MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))
        Loop
        YYStripTabs = Trim(MyStr)
    End Function
    '生成Doxygen样式的函数注释
    Function GetFunctionName()
        Dim Header As String
        Dim Reti As String
        Dim RetTp As String
        Dim Loc As Integer
        Dim Loc2 As String
        Dim fcName As String
        Dim iPrm As Integer
        Dim iPrmA As Integer
        Dim prms As String
        Dim ParamArr() As String
        Dim Descr As String
        Dim last As Integer
        Dim dsCpp
        Dim selection As EnvDTE.TextSelection
        'MsgBox("start")
        dsCpp = EnvDTE.Constants.dsCPP
        If DTE.ActiveDocument.Language = dsCpp Then
            DTE.ActiveDocument.Selection.SelectLine()
            'MsgBox(DTE.ActiveDocument.Selection.Text)
            Header = YYStripTabs(Trim(DTE.ActiveDocument.Selection.Text))
            'Get the function return type.
            'RetTp 返回类型
            'MsgBox(Header)
            If Header <> "" Then
                Reti = InStr(Header, " ")
                Loc = InStr(Header, "(")
                If Reti < Loc Then
                    RetTp = Left(Header, Reti)
                    Header = Right(Header, Len(Header) - Reti)
                End If
                'Get the function name.
                'fcName 函数名城
                'MsgBox(Header)
                Loc = InStr(Header, "(") - 1
                Loc2 = InStr(Header, ")")
                Dim i As Integer
                i = 0
                Do While Loc2 <= 0
                    DTE.ActiveDocument.Selection.LineDown(True, 1)
                    DTE.ActiveDocument.Selection.SelectLine()
                    Header = Header + YYStripTabs(Trim(DTE.ActiveDocument.Selection.Text))
                    Loc2 = InStr(Header, ")")
                    i = i + 1
                Loop
                DTE.ActiveDocument.Selection.LineUp(True, 1)
            End If
            If Loc > 0 And Loc2 > 0 Then 'make sure there is a '(' and a ')'
                fcName = Left(Header, Loc)
                Header = Right(Header, Len(Header) - Len(fcName))
                'Do we have storage type on the return type?
                Trim(fcName)
                If InStr(fcName, " ") <> 0 Then
                    RetTp = RetTp + Left(fcName, InStr(fcName, " "))
                    fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))
                End If
                Return fcName
            Else
                Return ""
            End If
        ElseIf DTE.ActiveDocument.Language = "CSharp" Then
            Try
                Dim projectItem As ProjectItem = DTE.ActiveDocument.ProjectItem
                Dim fileCodeModel As FileCodeModel = projectItem.FileCodeModel
                '得到当前选定的内容
                Dim selectText As TextSelection = DTE.ActiveDocument.Selection
                '获取到当前光标的位置
                Dim point As TextPoint = selectText.ActivePoint
                Dim codeElement As CodeElement = fileCodeModel.CodeElementFromPoint(point, vsCMElement.vsCMElementFunction)
                If (codeElement Is Nothing) Then
                    Return ""
                Else
                    Return codeElement.Name
                End If
            Catch ex As Exception
                Return ""
            End Try
        Else
            Return ""
        End If
    End Function
    'Function GetFunctionNameTest()
    '    ' Before running this example, open a code document from a
    '    ' project and place the insertion point inside a class definition.
    '    Try
    '        Dim projectItem As ProjectItem = DTE.ActiveDocument.ProjectItem
    '        Dim fileCodeModel As FileCodeModel = projectItem.FileCodeModel
    '        '得到当前选定的内容
    '        Dim selectText As TextSelection = DTE.ActiveDocument.Selection
    '        '获取到当前光标的位置
    '        Dim point As TextPoint = selectText.ActivePoint
    '        Dim codeElement As CodeElement = fileCodeModel.CodeElementFromPoint(point, vsCMElement.vsCMElementFunction)
    '        If (codeElement Is Nothing) Then
    '            Return ""
    '        Else
    '            MessageBox.Show(codeElement.Name)
    '            Return codeElement.Name
    '        End If
    '    Catch ex As Exception
    '        Return ""
    '    End Try
    'End Function
End Module

经过修改后的代代码如下:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.IO
Imports System.Diagnostics
Imports EnvDTE.Constants
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Threading


Public Module CodeReview
    Public Class CodeReviewRecord
        Public sMethod, sProblem, sSuggest, sModifyTime As String
        Public nLine As Long
        Dim sFileName As String
        Friend Function Init()
            Const passedString = "d:\\CodeReview"
            Dim sRec As String
            Dim selection As EnvDTE.TextSelection
            Dim startPoint As EnvDTE.EditPoint
            Dim StrArray() As String
            'Get record file name
            sFileName = DTE.ActiveDocument.FullName
            'MsgBox(sFileName + "||" + passedString)

            'StrArray = Split(sFileName, passedString)
            'If StrArray.Length < 2 Then
            '    MsgBox("the file which your are editting is not controlled by Starteam, record can not write to file.1")
            '    Return False
            'End If
            'sFileName = StrArray(0)
            'Dim Dirs() As String
            'Dirs = Split(sFileName, "\")
            'If Dirs.Length < 3 Then
            '    MsgBox("the file which your are editting is not controlled by Starteam, record can not write to file.2")
            '    Return False
            'End If
            Dim DateStr As String
            DateStr = Format(Now(), "yyyyMMdd")
            'Dim proj As String
            'proj = Dirs(Dirs.Length - 2)
            sFileName = passedString + "\代码检查记录_" + DateStr + ".txt"
            selection = DTE.ActiveDocument.Selection()
            startPoint = selection.TopPoint.CreateEditPoint()
            nLine = startPoint.Line
            'sMethod = GetFunctionName()
            sModifyTime = System.DateTime.Now.AddDays(1).ToString("yyyyMMdd")
            Return True
        End Function
        Public Sub GenRecord(ByRef sRec As String)
            sRec = vbCrLf + "[时间]:  " + System.DateTime.Now.ToString() + vbCrLf
            sRec = sRec + "[组件]:  " + DTE.ActiveWindow.Project.Name + vbCrLf
            sRec = sRec + "[文件]:  " + DTE.ActiveDocument.FullName + vbCrLf
            sRec = sRec + "[行数]:  " + nLine.ToString() + vbCrLf
            sRec = sRec + "[方法]:  " + sMethod + vbCrLf
            sRec = sRec + "[问题]:  " + sProblem + vbCrLf
            sRec = sRec + "[建议]:  " + sSuggest + vbCrLf
            sRec = sRec + "--------------------" + vbCrLf
            sRec = sRec + "[计划修改时间]:  " + sModifyTime + vbCrLf
            sRec = sRec + "[实际修改时间]:  " + vbCrLf
            sRec = sRec + "[修改结果说明]:  " + vbCrLf
            sRec = sRec + "[验证情况]:  " + vbCrLf
            sRec = sRec + "[验证人]:  " + vbCrLf
            sRec = sRec + "______________________________________________________________________"
        End Sub
        Public Sub Write(ByRef sRec As String)
            Dim file As System.IO.StreamWriter
            file = My.Computer.FileSystem.OpenTextFileWriter(sFileName, True)
            file.WriteLine(sRec)
            file.Close()
        End Sub
    End Class
    Public Class CodeReviewForm
        Inherits System.Windows.Forms.Form
        Private tRec As CodeReviewRecord
        Public WithEvents FuncName As System.Windows.Forms.RichTextBox
        Public WithEvents Problem As System.Windows.Forms.RichTextBox
        Public WithEvents Suggest As System.Windows.Forms.RichTextBox
        Public WithEvents ModifyTime As System.Windows.Forms.RichTextBox
        Friend text1, text2, text3, text4 As System.Windows.Forms.Label
        Friend WithEvents btnSure As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        Public Function Init()
            Return tRec.Init()
        End Function
        Public Sub New()
            MyBase.New()
            tRec = New CodeReviewRecord
            Width = 600
            Height = 520
            SuspendLayout()
            text1 = New System.Windows.Forms.Label
            text1.Location = New System.Drawing.Point(5, 5)
            text1.Name = "lblFuncName"
            text1.Width = 170
            text1.TabIndex = 0
            text1.ForeColor = Color.Blue
            text1.Text = "方法名" ' "function name"
            FuncName = New System.Windows.Forms.RichTextBox
            FuncName.Location = New System.Drawing.Point(5, 25)
            FuncName.Name = "txtFuncName"
            FuncName.Width = 580
            FuncName.Height = 40
            FuncName.TabIndex = 10
            FuncName.Text = GetFunctionName()  'tRec.sMethod 
            text2 = New System.Windows.Forms.Label
            text2.Location = New System.Drawing.Point(5, 75)
            text2.Name = "lblProblem"
            text2.Width = 170
            text2.TabIndex = 0
            text2.ForeColor = Color.Blue
            text2.Text = "问题描述" '"problem description"
            Dim selection As EnvDTE.TextSelection
            selection = DTE.ActiveDocument.Selection()
            Problem = New System.Windows.Forms.RichTextBox
            Problem.Location = New System.Drawing.Point(5, 95)
            Problem.Name = "txtProblem"
            Problem.Width = 580
            Problem.Height = 160
            Problem.TabIndex = 20
            Problem.Text = selection.Text ' tRec.sProblem
            text3 = New System.Windows.Forms.Label
            text3.Location = New System.Drawing.Point(5, 265) ' 165)
            text3.Name = "lblSuggest"
            text3.Width = 170
            text3.TabIndex = 0
            text3.ForeColor = Color.Blue
            text3.Text = "修改建议" ' "fix suggestion"
            Suggest = New System.Windows.Forms.RichTextBox
            Suggest.Location = New System.Drawing.Point(5, 285) '185)
            Suggest.Name = "txtSuggest"
            Suggest.Width = 580
            Suggest.Height = 80
            Suggest.TabIndex = 30
            Suggest.Text = tRec.sSuggest
            text4 = New System.Windows.Forms.Label
            text4.Location = New System.Drawing.Point(5, 375) ' 165)
            text4.Name = "lblModifyTime"
            text4.Width = 170
            text4.TabIndex = 0
            text4.ForeColor = Color.Blue
            text4.Text = "修改时间" ' "fix suggestion"
            ModifyTime = New System.Windows.Forms.RichTextBox
            ModifyTime.Location = New System.Drawing.Point(5, 395) '185)
            ModifyTime.Name = "txtModifyTime"
            ModifyTime.Width = 580
            ModifyTime.Height = 40
            ModifyTime.TabIndex = 40
            ModifyTime.Text = System.DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") 'tRec.sModifyTime
            btnSure = New System.Windows.Forms.Button
            btnSure.Location = New System.Drawing.Point(200, 450) '250)
            btnSure.Name = "btnSure"
            btnSure.Width = 70
            btnSure.TabIndex = 50
            btnSure.Text = "确 定"  '"OK(&O)"
            btnCancel = New System.Windows.Forms.Button
            btnCancel.Location = New System.Drawing.Point(320, 450) ' 250)
            btnCancel.Name = "btnCancel"
            btnCancel.Width = 70
            btnCancel.TabIndex = 60
            btnCancel.Text = "取 消" ' "Cancel(&C)"
            Controls.Add(FuncName)
            Controls.Add(Problem)
            Controls.Add(Suggest)
            Controls.Add(ModifyTime)
            Controls.Add(text1)
            Controls.Add(text2)
            Controls.Add(text3)
            Controls.Add(text4)
            Controls.Add(btnSure)
            Controls.Add(btnCancel)
            AcceptButton = btnSure
            CancelButton = btnCancel
            AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly
            StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
            Name = "Code Review Form"
            Text = "Add CodeReview record"
            ResumeLayout(False)
            TopLevel = True
        End Sub
        Private Sub Sure_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSure.Click
            tRec.sMethod = FuncName.Text.Trim()
            tRec.sProblem = Problem.Text.Trim()
            tRec.sSuggest = Suggest.Text.Trim()
            tRec.sModifyTime = ModifyTime.Text.Trim()
            Dim s As String
            tRec.GenRecord(s)
            tRec.Write(s)
            Close()
        End Sub
        Private Sub Cancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Close()
        End Sub
    End Class
    Public Sub AddCodeReviewRecord()
        Dim sf As New CodeReviewForm
        If (sf.Init()) Then
            sf.BringToFront()
            sf.ShowDialog()
            sf.Activate()
            sf.Focus()
        End If
    End Sub
    Function YYStripTabs(ByVal MyStr)
        Do While InStr(MyStr, vbTab) <> 0
            MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))
        Loop
        YYStripTabs = Trim(MyStr)
    End Function
    '生成Doxygen样式的函数注释
    Function GetFunctionName()
        Dim Header As String
        Dim Reti As String
        Dim RetTp As String
        Dim Loc As Integer
        Dim Loc2 As String
        Dim fcName As String
        Dim iPrm As Integer
        Dim iPrmA As Integer
        Dim prms As String
        Dim ParamArr() As String
        Dim Descr As String
        Dim last As Integer
        Dim dsCpp
        Dim selection As EnvDTE.TextSelection
        'MsgBox("start")
        dsCpp = EnvDTE.Constants.dsCPP
        If DTE.ActiveDocument.Language = dsCpp Then
            DTE.ActiveDocument.Selection.SelectLine()
            'MsgBox(DTE.ActiveDocument.Selection.Text)
            Header = YYStripTabs(Trim(DTE.ActiveDocument.Selection.Text))
            'Get the function return type.
            'RetTp 返回类型
            'MsgBox(Header)
            If Header <> "" Then
                Reti = InStr(Header, " ")
                Loc = InStr(Header, "(")
                If Reti < Loc Then
                    RetTp = Left(Header, Reti)
                    Header = Right(Header, Len(Header) - Reti)
                End If
                'Get the function name.
                'fcName 函数名城
                'MsgBox(Header)
                Loc = InStr(Header, "(") - 1
                Loc2 = InStr(Header, ")")
                Dim i As Integer
                i = 0
                Do While Loc2 <= 0
                    DTE.ActiveDocument.Selection.LineDown(True, 1)
                    DTE.ActiveDocument.Selection.SelectLine()
                    Header = Header + YYStripTabs(Trim(DTE.ActiveDocument.Selection.Text))
                    Loc2 = InStr(Header, ")")
                    i = i + 1
                Loop
                DTE.ActiveDocument.Selection.LineUp(True, 1)
            End If
            If Loc > 0 And Loc2 > 0 Then 'make sure there is a '(' and a ')'
                fcName = Left(Header, Loc)
                Header = Right(Header, Len(Header) - Len(fcName))
                'Do we have storage type on the return type?
                Trim(fcName)
                If InStr(fcName, " ") <> 0 Then
                    RetTp = RetTp + Left(fcName, InStr(fcName, " "))
                    fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))
                End If
                Return fcName
            Else
                Return ""
            End If
        ElseIf DTE.ActiveDocument.Language = "CSharp" Then
            Try
                Dim projectItem As ProjectItem = DTE.ActiveDocument.ProjectItem
                Dim fileCodeModel As FileCodeModel = projectItem.FileCodeModel
                '得到当前选定的内容
                Dim selectText As TextSelection = DTE.ActiveDocument.Selection
                '获取到当前光标的位置
                Dim point As TextPoint = selectText.ActivePoint
                Dim codeElement As CodeElement = fileCodeModel.CodeElementFromPoint(point, vsCMElement.vsCMElementFunction)
                If (codeElement Is Nothing) Then
                    Return ""
                Else
                    Return codeElement.Name
                End If
            Catch ex As Exception
                Return ""
            End Try
        Else
            Return ""
        End If
    End Function
    'Function GetFunctionNameTest()
    '    ' Before running this example, open a code document from a
    '    ' project and place the insertion point inside a class definition.
    '    Try
    '        Dim projectItem As ProjectItem = DTE.ActiveDocument.ProjectItem
    '        Dim fileCodeModel As FileCodeModel = projectItem.FileCodeModel
    '        '得到当前选定的内容
    '        Dim selectText As TextSelection = DTE.ActiveDocument.Selection
    '        '获取到当前光标的位置
    '        Dim point As TextPoint = selectText.ActivePoint
    '        Dim codeElement As CodeElement = fileCodeModel.CodeElementFromPoint(point, vsCMElement.vsCMElementFunction)
    '        If (codeElement Is Nothing) Then
    '            Return ""
    '        Else
    '            MessageBox.Show(codeElement.Name)
    '            Return codeElement.Name
    '        End If
    '    Catch ex As Exception
    '        Return ""
    '    End Try
    'End Function
End Module

使用方法:

1. 将附件中的宏添加到VS的宏资源管理器中,再将宏添加到VS的工具栏

2. 建立D:\\CodeReview目录;在代码里写死的,想放哪里把代码改下即可。当然也可以获取到当前解决方案的目录,本人比较懒,直接写死了

3. 选中代码

VS中的CodeReview宏命令

4.点击工具栏上的按扭后会弹出对话框

VS中的CodeReview宏命令

VS中的CodeReview宏命令

5.点击确定后D:\CodeReivew下的记录如下

VS CodeReview
VS中的CodeReview宏命令

相关文章: