I have C++ code which uses such approach:
#if defined(CONSTANT)
..
// Some code
#else
// Some other code
I was told I can use similar approach in C#-because I need to rewrite this C++ project to C#. But there is one problem. From the documentation I have seen that in C# if I use
#define CONSTANT
this is only visible in the file where it was declared.
But I don't want this. I want this CONSTANT
to be visible in all classes?
I think one solution is to declare such constants in the Project Settings etc - but here is my first question: In that case do I need to ship some additional file with my DLL? Or these constants will be embedded in DLL?
Finally, to avoid above problems I am thinking about approach of using just public const values in C#. Like
if(Globals.SomeConstant == SOMEVALUE)
// Do this
else
// Do smth else
And then depending on the configuration I will set default values during declaration of Globals.SomeConstant
to the value I need, compile the DLL and ship it. Does this sound ok and will it work like this? Will the default values be assigned and read properly inside DLL methods? (will they work like #ifdefs
?)
I know I will need to recompile to change the code but that is ok.