Considering target C# version
See original GitHub issueCurrent code uses C# 6.0. Since the release of MSBuild 15 (and Visual Studio 2017), C# 7.0 is available. Currently project files don’t reflect the existence of a C# version higher than 6.0, still stating ‘default’ in the advanced build properties for ‘Language Version’. We’d gain the following benefits from switching to C# 7.0:
Benefits
out
variables:- You can declare
out
values inline as arguments to the method where they are used.
- You can declare
- Tuples
- You can create lightweight, unnamed types that contain multiple public fields. Compilers and IDE tools understand the semantics of these types.
- Pattern Matching
- You can create branching logic based on arbitrary types and values of the members of those types.
ref
locals and returns- Method arguments and local variables can be references to other storage.
- Local Functions
- You can nest functions inside other functions to limit their scope and visibility.
- More expression-bodied members
- The list of members that can be authored using expressions has grown.
- throw Expressions
- You can throw exceptions in code constructs that previously were not allowed because throw was a statement.
- Generalized
async
return types- Methods declared with the
async
modifier can return other types in addition toTask
andTask<T>
.
- Methods declared with the
- Numeric literal syntax improvements
- New tokens improve readability for numeric constants.
More info on all these additions can be found on Microsoft’s .NET documentation, from where the short explanation seen in this issue was taken.
Limitations
Support of C# 7.0 is limited. Only MSBuild and roslyn can compile C# 7.0 at this point, and until Mono finishes the switch to MSBuild/roslyn with Mono 5.0, Mono won’t be able to compile. On the Microsoft side of things, the situation is not that much rosier, with only Visual Studio 2017, Visual Studio Code and Visual Studio for Mac being able to handle C# 7.0 natively. VS 2015 can be made to work with C# 7.0, but it is most certainly not a painfree experience, and I am not certain if any of these benefits outweigh the limitations that we’d impose on ourselves.
Scope of the issue
At the moment of writing of this issue, 79 IDE Messages are being generated in Visual Studio 2017 due to a mismatch between the default C# version in Visual Studio 2017 (C# 7.0) and the actual C# version used (C# 6.0), which can be fixed by switching the Language version to explicit 6.0, or to explicit 7.0 and using those C# 7.0 features. Both code in this repository as well as in ppy/osu-framework is affected by this issue, so feel free to move the issue to osu-framework, should the issue be more appropriate over there.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Didn’t realise we can explicitly force 6. We should be doing this until mono 5.0 is officially out.
They’re called anonymous types.