I know that I can use preprocessor directives in C#
to enable/disable compilation of some part of code.
If I define a directive in the same file, it works fine:
#define LINQ_ENABLED
using System;
using System.Collections.Generic;
#if LINQ_ENABLED
using System.Linq;
#endif
Now, I'm used in C++
at putting all this configuration directives inside a single header file, and include it in all files where I need such directives.
If I do the same in C#
something doesn't work:
//Config.cs
#define LINQ_ENABLED
//MyClass.cs
#define LINQ_ENABLED
using System;
using System.Collections.Generic;
#if LINQ_ENABLED
using System.Linq;
#endif
I also tried the following but seems that I can't define a directive inside a namespace:
//Config.cs
namespace Conf{
#define LINQ_ENABLED
}
//MyClass.cs
#define LINQ_ENABLED
using System;
using System.Collections.Generic;
using Conf;
#if LINQ_ENABLED
using System.Linq;
#endif
- What am I doing wrong?
- What's the right way of using preprocessor across different files in
C#
? - Is there any better way to do that?