Re: Introducing C# Source Generators
От: Serginio1 СССР https://habrahabr.ru/users/serginio1/topics/
Дата: 16.09.20 16:28
Оценка:
Здравствуйте, Serginio1, Вы писали:

https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9

Two final features support C# code generators. C# code generators are a component you can write that is similar to a roslyn analyzer or code fix. The difference is that code generators analyze code and write new source code files as part of the compilation process. A typical code generator searches code for attributes or other conventions.

A code generator read attributes or other code elements using the Roslyn analysis APIs. From that information, it adds new code to the compilation. Source generators can only add code; they aren't allowed to modify any existing code in the compilation.

The two features added for code generators are extensions to partial method syntax, and module initializers. First, the changes to partial methods. Before C# 9.0, partial methods are private but can't specify an access modifier, have a void return, and can't have out parameters. These restrictions meant that if no method implementation is provided, the compiler removes all calls to the partial method. C# 9.0 removes these restrictions, but requires that partial method declarations have an implementation. Code generators can provide that implementation. To avoid introducing a breaking change, the compiler considers any partial method without an access modifier to follow the old rules. If the partial method includes the private access modifier, the new rules govern that partial method.

The second new feature for code generators is module initializers. Module initializers are methods that have the ModuleInitializerAttribute attribute attached to them. These methods will be called by the runtime when the assembly loads. A module initializer method:

Must be static
Must be parameterless
Must return void
Must not be a generic method
Must not be contained in a generic class
Must be accessible from the containing module

и солнце б утром не вставало, когда бы не было меня
Re: Introducing C# Source Generators
От: Serginio1 СССР https://habrahabr.ru/users/serginio1/topics/
Дата: 22.01.21 07:42
Оценка:
Visual Studio 2019 v16.9 Preview 3 is Available Today

Visual Studio 2019 v16.9 Preview 3 можно видеть нагенеренный код
и солнце б утром не вставало, когда бы не было меня
Re: Introducing C# Source Generators
От: Serginio1 СССР https://habrahabr.ru/users/serginio1/topics/
Дата: 28.01.21 07:46
Оценка:
Using C# Source Generators to create an external DSL
и солнце б утром не вставало, когда бы не было меня
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.