Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 6 source generators and C# 9 syntax

If source generator projects must target netstandard2.0 (C# 7.3), how and why do the examples in the .NET 6 incremental generator documentation use C# 9 syntax like static anonymous functions?

From the doc, formatted for width:

IncrementalValuesProvider<AdditionalText> textFiles =
   context.AdditionalTextsProvider.Where(static file =>
      file.Path.EndsWith(".txt"));
like image 774
Kevin Krumwiede Avatar asked Feb 17 '26 07:02

Kevin Krumwiede


1 Answers

Just change the C# version in the .csproj file to 9, as in <LangVersion>9.0</LangVersion>

like image 82
yoel halb Avatar answered Feb 18 '26 21:02

yoel halb