Here's a quick and dirty way to do it using a simple text replace:
- Format your C# file so that all of the indentations are lined up. You can do this in
Edit
> Advanced
> Format Document
- Open up text replace with
Ctrl+H
- Set the "Text to Find" field this
"^ {"
.
- Set the "Replace" field to this
" {System.Diagnostics.Debugger.Break();"
- Click the little "Use Regular Expressions" button in the window
- Click "Replace All" or hit
Alt+A
- If your file has any classes with nested enums, classes, or structs, you'll have some compiler errors. Remove the Debug calls from them until your code compiles. If your nested classes have their own methods, you'll have to run this process again with more tabs in the replace strings.
How this works: This uses the Visual Studio document formatter and assumes that all methods in a file start with two tabs and then a "{". So any line that starts with two tabs and a "{" will get replaced with the same two tabs, the same "{", and a call to the Debugger.
If your file has nested enums etc., you'll get compiler errors because the text replace doesn't discriminate between methods and enums. For example, you'll see this:
enum MyColors
{ System.Diagnostics.Debugger.Break(); //error here
Red,
Green,
Blue,
}
If you want the ability to disable these breakpoints, the best way I can think of is a simple bool. Somewhere in your code, insert this:
#if DEBUG
private static bool _ignoreDebug = false;
#endif
(I put the #if DEBUG
in there as a flag that this code is only for debugging. It's not necessary) Then in step #4 above, use this replace string instead:
" {if(!_ignoreDebug){System.Diagnostics.Debugger.Break();}"
Then when you hit a breakpoint and don't want to hit any more, in the watch window type this and hit enter _ignoreDebug = true
. To turn it back on you'll need to insert a manual breakpoint somewhere that has access to the _ignoreDebug
bool.
To remove all of this from your code, either do another text replace, or just edit undo everything.