Is there a version of Debug.Assert () that checks the release condition?

I need a version of Debug.Assert (), which in the release build will still execute the code in the condition parameter, but will not display the approval dialog if the approval fails. Is there such a tool in .NET 3.5 or should I implement it myself (if I can)?

+2
source share
2 answers

Use Trace.Assert for this, it also works in release mode. See the documentation on how to use listeners to use a different method than creating a dialog. Exposure:

DefaultTraceListener. DefaultTraceListener Listeners, . DefaultTraceListener <clear> < > <trace> , <remove> < > <trace> , Clear Listeners (System.Diagnostics.Trace.Listeners.Clear()).

, :

#if (!DEBUG)
    System.Diagnostics.Trace.Listeners.Clear();
#endif
+4

Debug.Assert?

bool isOk = CodeToBeExecuted();
Debug.Assert(isOk == true);
0

All Articles