输入文件(或类)时会中断 [英] break whenever a file (or class) is entered

查看:141
本文介绍了输入文件(或类)时会中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中,每当输入某个文件(或类)时,是否有任何方法使调试器中断?请不要回答在每个方法开始时设置断点:)

In Visual Studio, is there any way to make the debugger break whenever a certain file (or class) is entered? Please don't answer "just set a breakpoint at the beginning of every method" :)

我正在使用C#。

推荐答案

宏可以是你的朋友。这是一个宏,它将为当前类中的每个方法添加一个断点(将光标放在该类中的某处,然后再运行它)。

Macros can be your friend. Here is a macro that will add a breakpoint to every method in the current class (put the cursor somewhere in the class before running it).

Public Module ClassBreak
    Public Sub BreakOnAnyMember()
        Dim debugger As EnvDTE.Debugger = DTE.Debugger
        Dim sel As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
        Dim editPoint As EnvDTE.EditPoint = sel.ActivePoint.CreateEditPoint()
        Dim classElem As EnvDTE.CodeElement = editPoint.CodeElement(vsCMElement.vsCMElementClass)

        If Not classElem Is Nothing Then
            For Each member As EnvDTE.CodeElement In classElem.Children
                If member.Kind = vsCMElement.vsCMElementFunction Then
                    debugger.Breakpoints.Add(member.FullName)
                End If
            Next
        End If
    End Sub

End Module

编辑:已更新至通过函数名添加断点,而不是文件/行号。在断点窗口中,感觉更好,更易于识别。

Updated to add breakpoint by function name, rather than file/line number. It 'feels' better and will be easier to recognise in the breakpoints window.

这篇关于输入文件(或类)时会中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆