问题描述
尽管由于 #define
是预处理程序指令而导致不可能,但我还是想问一下:
Even though it should be impossible due to #define
being a pre-processor directive I'd like to ask:
是否可以在实际程序中获得 #define
'd变量的列表?分别在项目属性中定义的条件编译符号列表。
Is it possible to get a list of the #define
'd variables within the actual program? Respectively, a list of conditional compilation symbols, defined within the project's properties.
我为什么需要它?
我是使用符号管理扩展。我正在尝试获取它们的列表,以将它们添加到我的关于窗口中,例如
Why would I need that?I'm managing extensions by using symbols. I'm trying to get a List of them to add them in my about window like
Enabled Extensions:
CUSTOMER1_ABC_EXTENSION
CUSTOMER2_XYZ_EXTENSION
无需为每个扩展名编写特定代码。
Without writing specific code for each extension.
推荐答案
看来,规范的答案是您无法做到。 的MSDN文档说:
It would appear that the cannonical answer is that you cannot do it. The MSDN documentation for #define says:
这将建议您最好使用反射。也许您可以使用类来装饰扩展并提供您可以测试的运行时信息。
This would suggest that you might be better off using reflection. Maybe you could use an Attribute class to decorate the extensions and provide run-time information that you can test for.
这篇关于获取#define变量的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!