Get a list of #define variables

Although this should be impossible due to the fact that #define is a preprocessor directive, I would like to ask:

Is it possible to get a list of #define 'd variables in a real program? Accordingly, a list of conditional compilation symbols defined in the project properties.

Why do I need it? I manage extensions using characters. I am trying to get a list of them to add them to my window, for example

 Enabled Extensions: CUSTOMER1_ABC_EXTENSION CUSTOMER2_XYZ_EXTENSION 

Without writing specific code for each extension.

+5
source share
2 answers

It would seem that the canonical answer is that you cannot do this. The MSDN documentation for # define says:

The volume of a character created with #define is the file in which the character was defined.

This may mean that you are better off using reflection. Perhaps you can use the Attribute class to decorate extensions and provide runtime information that you can verify.

+1
source

Solved it using

 public static class BuildVariables { public static List<string> DefinedVariables = new List<string>() { #if CUSTOMER1_ABC_EXTENSION "CUSTOMER1_ABC_EXTENSION", #endif #if CUSTOMER2_XYZ_EXTENSION "CUSTOMER2_XYZ_EXTENSION", #endif }; } 

This is pretty dirty and needs to be changed every time a new character is entered. I do not like it.

0
source

Source: https://habr.com/ru/post/1212084/


All Articles