作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 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();
};
我想实现以下目标:如果 native c++ 预处理器指令是 active,则托管的 ConditionalAttribute 也应该是 active。另一方面,如果 native c++ 预处理器指令是inactive,则托管的 ConditionalAttribute 应该是inactive。
最佳答案
下面的标准文件很旧。但假设,可能仍然有效。
https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-372.pdf
转到第 29.4.3 节(您可以在下面找到有关 c++/CLI 中的条件属性的内容)。
C++/CLI does not provide this ability; although attributes of this type are accepted, they have no affect on code generation or execution.
关于c++ - 如何在 C++-CLI 中使用 ConditionalAttribute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50267351/
我是一名优秀的程序员,十分优秀!