Skip to content

Support code generation targeting C# < 9 #4

Closed as not planned
Closed as not planned

Description

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:

  1. Nullable ref annotations (C# 8)
  2. Function pointers (C# 9)
  3. '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.

  4. '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.

Activity

  1. AArnott commented on Jun 16, 2022

    @AArnott
    MemberAuthor

    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.

  2. added
    wontfix
    on Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementwontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions