Support code generation targeting C# < 9
AArnott opened this issue · 1 comments
Source generators work in projects that target less than the C# 9 language version, so the generator should take the LangVersion
into account and generate valid code given that target version.
Examples of C# features the generated code may rely on that require newer language versions include:
- Nullable ref annotations (C# 8)
- Function pointers (C# 9)
- 'null pointer constant pattern':
Windows.Win32.PCWSTR.g.cs(52,15,52,19): error CS8370: Feature 'null pointer constant pattern' is not available in C# 7.3. Please use language version 8.0 or greater.
- 'readonly members'
Windows.Win32.D2D_MATRIX_4X4_F.g.cs(66,22,66,30): error CS8370: Feature 'readonly members' is not available in C# 7.3. Please use language version 8.0 or greater.
Note that C# 9 does work on projects that target .NET Framework as well as .NET Core 3.1. But there are features of C# 8+ that do not work on .NET Framework, such as default interface methods from C# 8 or certain calling conventions of function pointers. By avoiding use of such features, many projects have successfully targeted .NET Framework while compiling with the C# 9 language version.
This becomes less of a priority as time goes by, and it's already so low relative to other issues we won't likely get to it while there is any interest.