我有一个C++-CLI类,它公开了一个用C++实现的分析基础结构。
在C++中,我有预处理器指令PROFILING_ENABLED来确定侵入性分析函数是否在代码中。
当向托管代码公开这些代码时,我认为使用托管ConditionalAttribute是合适的。但我很难理解语法。
以下是我的尝试:
#ifdef PROFILING_ENABLED
// c++ macros are defined and active on the project level, I would like the
// conditional attribute to be active as well.
#define MANAGED_PROFILING_ENABLED
// how do I define the managed conditional "MANAGED_PROFILING_ENABLED" in C++-CLI?
#endif
public ref class Profiler
{
public:
[ConditionalAttribute("MANAGED_PROFILING_ENABLED")] // this compile but always inactive
static void PushRange(System::String ^ name, Color color);
[ConditionalAttribute("MANAGED_PROFILING_ENABLED")]
static void PopRange();
};我想实现以下目标:如果本机c++预处理器指令是active,那么托管ConditionalAttribute也应该是active。另一方面,如果本机c++预处理器指令是非活动,则托管ConditionalAttribute应该是非活动。
发布于 2018-05-14 17:18:53
下面的标准文件很老了。但假设这一点,可能仍然有效。
https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-372.pdf
转到29.4.3节(您可以在下面的c++/CLI中找到关于条件属性的内容)。
C++/CLI不提供这种能力;虽然接受这种类型的属性,但它们对代码生成或执行没有影响。
https://stackoverflow.com/questions/50267351
复制相似问题