NET Standard 2.0 target frameworkĪdd NuGet packages and Create a new class library project with.Here are some basic steps that can be used for source generator project setup. Projects that contain source generators are just ordinary class libraries that require some adjustments. Another advantage is the possibility to catch errors during compile time instead of catching them during runtime. An alternative to this approach is runtime reflection which is used during the startup of an application and therefore can prolong the startup time. There are multiple advantages of using source generators which include better performance because the source generator is analyzing code during the compilation. The image below shows the process which happens during compilation if a developer uses source generators. This approach could prevent a mistyped string literal leading to a request not hitting the correct controller. Another usage of source generators can be in ASP.NET Core applications routing where it can be strongly typed with the necessary strings being generated as a compile-time detail. It can also shift the controller discovery phase from startup to compile time, reducing startup time. The most common use case for source generators is code analysis during compilation, after which more code is generated and added to the compilation object. NET Compiler Platform ("Roslyn") SDK which allows developers to generate source files during compilation and add those files to the compilation object.įor this to be possible, source generators can retrieve a compilation object which contains all the code a developer has written. Last modified on Mon What are Source Generators?Īccording to the official documentation, a source generator is a part of the.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |