views:

73

answers:

3

Having recently learned of the DebuggerDisplay attribute, I've found it quite useful. However, one thing that surprises me is that it doesn't have a [ConditionalAttribute("DEBUG")] attribute attached to it. Is there some way to force this or is it a bad idea to try? Or does it not matter for some other reason?

A: 

I would think it would be a bad idea, because a lot of times the thing you're attaching the attribute to has some other use besides just showing it in the debugger, IMO.

Joseph
I think you may have misunderstood. I want to compile out the attribute, not the class.
MighMoS
+1  A: 

The [ConditionalAttribute("DEBUG")] is only used for optimising out method calls.

If you really want to remove these from your builds you can use #ifdef so that the code is only compiled in release mode.

One thing to bear in mind is that you can still debug binaries in release mode, as long as you have the pdb files it shouldn't matter. Release mode just clears up variables sooner and applies some compiler optimisations

Matthew Steeples
Going farther would there be a way to find out if this information is saved in those .pdb files? If the release "binary" doesn't have them it would be fine.
MighMoS
It's saved in the dll rather than the pdb file. You can use a tool such as reflector to find this out. PDB files (as a summary) contain the details about the raw source code, line numbers etc
Matthew Steeples
A: 

As I often have to debug things in Release configuration builds that don't have the DEBUG directive, I would not want these hints to the debugger to be removed.

However, if you have some proprietary or confidential information in the way you display things when debugging that you don't want to make it into your release build, you may want to consider using the ConditionalAttribute or #if/#elif/#endif preprocessor directives to control what is emitted into your release builds.

For example, you could do:

#if DEBUG
[DebuggerDisplay...]
#endif
public class MyAwesomeClass
{
}

This would ensure the attribute is only emitted when the DEBUG directive is given.

Jeff Yates