1

How to set breakpoint on all the methods in a class in VS 2012.
Similar question is posted at How do I set a breakpoint on every access to a class
but the solutions are not working with VS2012

Community
  • 1
  • 1
meetjaydeep
  • 1,752
  • 4
  • 25
  • 39

2 Answers2

0

You may think of using Debugger.Break and inject it in every method that you want to analyze.

Injection can be done: by hand, or by some mechanism like AOP programming.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • I don't want to write code to add the breakpoint is there anything similar to Macros (VS2010) or maybe Addin. – meetjaydeep Jun 27 '13 at 11:12
  • @meetjaydeep: nor that I'm aware of. You may look on AOP. It's still the code, but written once :) – Tigran Jun 27 '13 at 11:14
0

You can position the caret within a class definition and call the following command (Language: C#) for Visual Commander to set breakpoints on all the methods:

using EnvDTE;
using EnvDTE80;

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
        if (ts == null)
            return;

        EnvDTE.CodeClass c = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementClass]
                    as EnvDTE.CodeClass;
        if (c == null)
            return;

        foreach(EnvDTE.CodeElement e in c.Members)
        {
            if(e.Kind== vsCMElement.vsCMElementFunction)
            {
                EnvDTE.TextPoint p = (e as EnvDTE.CodeFunction).GetStartPoint();
                DTE.Debugger.Breakpoints.Add("", p.Parent.Parent.FullName, p.Line);
            }
        }
    }
}
Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66