获取#define变量的列表 [英] Get a list of #define variables

查看:71
本文介绍了获取#define变量的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管由于 #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.

推荐答案

看来,规范的答案是您无法做到。 #define 的MSDN文档说:

It would appear that the cannonical answer is that you cannot do it. The MSDN documentation for #define says:


使用#define创建的符号范围是定义符号的文件。

The scope of a symbol that was created by using #define is the file in which the symbol was defined.

这将建议您最好使用反射。也许您可以使用属性类来装饰扩展并提供您可以测试的运行时信息。

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变量的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆