I have a C# codebase which is being edited in both VS 2013 and VS 2015 CTP 6. With CTP 6 has come C# v6 which requires "using static" on some imports.
Is there a way in which I can determine which version (either VS or C#) is being used such that I can use a preprocessor directive to use either "using" or "using static"?
e.g.
#if CS6
using static ...
#else
using ...
#endif
A preprocessor directive is my initial thought. If there is another way to do this I am all ears.
The static using
shouldn't be required; it is syntactic sugar that has been added to C# 6.0. You should always be able to specify the fully qualified name of a static method to call it, e.g. instead of
using System.Environment;
// class and method declaration elided
var path = GetFolderPath(...);
You could always have
// no static using here!
// class and method declaration elided
var path = System.Environment.GetFolderPath(...);
or, if you don't have a class of your own called System
(why would you do that?):
// still no static using here!
using System;
// class and method declaration elided
var path = Environment.GetFolderPath(...);
It isn't a breaking change if it doesn't break previously compilable code. Since there weren't static imports in C# before 6.0, this isn't a breaking change.
It is also not required. That would be a real breaking change.
If you want to work on a code base simultaneously with Visual Studio 2013 and Visual Studio 2015, you'll have to use the maximum common denominator which is C# 5.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With