此博客不推荐它:http: //blog.kalmbachnet.de/?posttid = 78
但无论如何我想要这样做.我想我需要换我Debug.Assert的用某种#if或#ifdef或类似的东西.另外,有没有人有一个很好的Debug.Assert示例C++ CLI?
假设我有以下变量:String^ validationError = bldError.ToString();
现在我希望做类似的事情:
#if (DEBUG)
Debug.Assert(false, "Got the following validation error:" + validationError);
#endif
Run Code Online (Sandbox Code Playgroud)
我怎样才能安全地进行C++ CLI,还有其他需要检查的问题吗?
编辑:根据答案,我提出了以下宏:
#ifdef _DEBUG
#define CLIASSERT(condition, ...) System::Diagnostics::Debug::Assert(condition, ##__VA_ARGS__)
#else
#define CLIASSERT(condition, ...) // This macro will completely evaporate in Release.
#endif
Run Code Online (Sandbox Code Playgroud)
这是一个用法示例:
String^ strValidationError = bldError.ToString();
CLIASSERT(false, L"Schema validation error: " + strValidationError);
Run Code Online (Sandbox Code Playgroud)
博文是准确的.看起来像这样:
#ifdef _DEBUG
Debug::Assert(...);
#endif
Run Code Online (Sandbox Code Playgroud)