Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide tracing code in Visual Studio IDE C#?

As I'm starting to put more tracing in my code, i'm realizing it adds a lot of clutter. I know Visual Studio allows you to hide and reveal code, however, i'd like to be able group code into "tracing" code and then hide it and reveal at will as i'm reading the code. I suppose it could do this either per file or per class or per function.

Is there any way to do this? What do you guys do?

Adding some clarification

The hide current feature kind of allows you to do this except that when the code is hidden, you can't tell if its tracing or not. You also can't say "hide all tracing code" and "reveal all tracing code" which is useful when reading a function depending on what you are trying to do.

like image 438
Mark Avatar asked Mar 29 '10 20:03

Mark


People also ask

How do I hide code in Visual Studio code?

The #Region directive enables you to collapse and hide sections of code in Visual Basic files. The #Region directive lets you specify a block of code that you can expand or collapse when using the Visual Studio code editor. The ability to hide code selectively makes your files more manageable and easier to read.

How do I go to a previous line in Visual Studio?

Navigate Forward/Backward Ctrl+–/Ctrl+Shift+– If you've moved from one location to another you can use the keyboard sequence <Ctrl>+– to move to the previous location and then you can return using Ctrl+Shift+–.


1 Answers

I'd advise against hiding it. If there's boilerplate code that's getting to the stage where it needs to be hidden away so that you can see the "real" code, then it's better to find a better way to seperate the concerns.

This is often true of tracing/debug code. Something I've looked at recently was to use a AOP framework to inject debug statements into other classes. Have a look at PostSharp, The example demonstrates how to do exactly that.

like image 163
TarkaDaal Avatar answered Oct 03 '22 11:10

TarkaDaal