Do debugging attributes such as [DebuggerDisplay] are compiled into Release binaries?

Having recently learned about the DebuggerDisplay attribute , I found it very useful. However, one thing surprises me: it does not have an attribute [ConditionalAttribute("DEBUG")]attached to it. Is there a way to make this or is it a bad idea to try? Or is it not important for some other reason?

+3
source share
4 answers

[ConditionalAttribute ("DEBUG")] is used only to optimize method calls.

If you really want to remove them from your collections, you can use #ifdef so that the code compiles only in release mode.

, , pdb, .

+4

Release, DEBUG, , .

, - , , , ConditionalAttribute #if/#elif/#endif , .

, :

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

, DEBUG.

+3

, , partial.

public partial class MyClass{
    //class details here
}

:

#if DEBUG
[DebuggerDisplay("DebuggerValue")]
public partial class MyClass{
    //anything needed for debugging purporses
}
#endif

DebuggerDisplay .

, #if DEBUG, Debug-Partials. , / .

+1

, , , , - , , , IMO.

0

Source: https://habr.com/ru/post/1712133/


All Articles