dotnet / dotnet/roslyn

How to obtain the CSharp language version in the Register Post Initialization Output method of IIncreatingGenerator.

Open
#80,604 0 comments 0 reactions 0 assignees View on GitHub
Area-IDE Feature - Source Generators
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

I am using the Register Post Initialization Output of I Creator Generator and want to add attributes that can guide source generation. At the same time, I need generic attributes, but this requires support from C # 11. Therefore, I need to determine the current language version and decide whether to add generic attributes.
In general generation, I can obtain language versions, such as:

```
context.RegisterSourceOutput(
context.ParseOptionsProvider,
(spc, parseOptions) =>
{
var languageVersion = parseOptions.LanguageVersion;
}
);
```

But in the Register Post Initialization Output, it seems to be not working. What should I do?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.