Can I set breakpoints to all methods in a class at once in Visual Studio?

前端 未结 6 1885
盖世英雄少女心
盖世英雄少女心 2020-12-28 13:06

I have 40-50 methods in a class, I want to add breakpoints to all of them. Can I add breakpoints to all of them at once?

6条回答
  •  一个人的身影
    2020-12-28 13:48

    Here's your macro, but it takes a while to set breakpoints on 1000+ functions... and it WILL slow down Visual Studio!

    Sub BreakAtEveryFunction()
        For Each project In DTE.Solution.Projects
            SetBreakpointOnEveryFunction(project)
        Next project
    End Sub
    
    
    ' Macro editor
    Sub SetBreakpointOnEveryFunction(ByVal project As Project)
        Dim cm = project.CodeModel
    
        ' Look for all the namespaces and classes in the 
        ' project.
        Dim list As List(Of CodeFunction)
        list = New List(Of CodeFunction)
        Dim ce As CodeElement
        For Each ce In cm.CodeElements
            If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then
                ' Determine whether that namespace or class 
                ' contains other classes.
                GetClass(ce, list)
            End If
        Next
    
        For Each cf As CodeFunction In list
    
            DTE.Debugger.Breakpoints.Add(cf.FullName)
        Next
    
    End Sub
    
    Sub GetClass(ByVal ct As CodeElement, ByRef list As List(Of CodeFunction))
    
        ' Determine whether there are nested namespaces or classes that 
        ' might contain other classes.
        Dim aspace As CodeNamespace
        Dim ce As CodeElement
        Dim cn As CodeNamespace
        Dim cc As CodeClass
        Dim elements As CodeElements
        If (TypeOf ct Is CodeNamespace) Then
            cn = CType(ct, CodeNamespace)
            elements = cn.Members
        Else
            cc = CType(ct, CodeClass)
            elements = cc.Members
        End If
        Try
            For Each ce In elements
                If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then
                    GetClass(ce, list)
                End If
                If (TypeOf ce Is CodeFunction) Then
                    list.Add(ce)
                End If
            Next
        Catch
        End Try
    End Sub
    

提交回复
热议问题