This blog does not recommend it: http://blog.kalmbachnet.de/?postid=78
But I want to do it anyway. I suppose I need to wrap my Debug.Assert with some sort of #if
or #ifdef
or something like that. Also, does anyone have a good example of a Debug.Assert in C++ CLI
?
Suppose I have the following variable: String^ validationError = bldError.ToString();
And now I wish to do something like:
#if (DEBUG)
Debug.Assert(false, "Got the following validation error:" + validationError);
#endif
How can I do it safely in C++ CLI
, and are there additional gotchas to check for?
EDIT: Based on the answers, I have come up with the following macro:
#ifdef _DEBUG
#define CLIASSERT(condition, ...) System::Diagnostics::Debug::Assert(condition, ##__VA_ARGS__)
#else
#define CLIASSERT(condition, ...) // This macro will completely evaporate in Release.
#endif
And here is an example of usage:
String^ strValidationError = bldError.ToString();
CLIASSERT(false, L"Schema validation error: " + strValidationError);