How to avoid conditionally using the same namespace in many files

I have code like the following in many files. The code is the same in every file.

#if SOMETHING
    using namespace1;
#else
    using namespace2;
#endif

However I don't want to have to maintain these same five lines in many files.

Ideally I would like to do something like this in a separate file:

#if SOMETHING
    var namespace = namespace1;
#else
    var namespace = namespace2;
#endif

And then in all the other files:

using namespace

How can I achieve something like this?

Jon Skeet
people
quotationmark

I would avoid having the same code in different namespaces twice to start with.

Just generate the code once, but then wherever you create an instance of the web service, specify the URL you want to connect to. (You probably want to centralize that code, mind you.)

Look at the properties in the web service - I'm sure one of them will be the base URL. Just because it defaults to one particular URL (ideally something invalid, so that you never end up making accidental calls to the wrong environment due to not setting it) doesn't mean you can't change it programmatically at execution time.

people

See more on this question at Stackoverflow