20:28 Target .NET Standard 2.0 22:37 Use IIncrementalGenerator 23:44 ForAttributeWithMetadataName() 27:37 Use Immutable, Read-Only Models ???? Code Generation 32:14 Naming Collisions 37:25 Avoid Package References 39:18 Be Nullable, but Be Forgiving 42:16 Reloading Sucks 46:47 Roslyn APIs can be "Surprising"
Excellent walkthrough. A few suggestions: You don't need to restart VS to observe changes to a source generator in another project. A `dotnet build-server shutdown` at the command line resets the build-server cache and forces the generators to re-run from scratch. Wrt. to nullable, I typically wrap generated code in `#nullable annotation`/`#nullable restore`. Then I do not have to use the damn-it operator in the generated code.
....sort of. You can intercept method invocations, but you can't change method bodies. Also, AFAIK, interceptors are still an experimental feature, so I didn't want to get into that in the talk - I had to enough to cover as-is :)
20:28 Target .NET Standard 2.0
22:37 Use IIncrementalGenerator
23:44 ForAttributeWithMetadataName()
27:37 Use Immutable, Read-Only Models
???? Code Generation
32:14 Naming Collisions
37:25 Avoid Package References
39:18 Be Nullable, but Be Forgiving
42:16 Reloading Sucks
46:47 Roslyn APIs can be "Surprising"
Excellent walkthrough. A few suggestions:
You don't need to restart VS to observe changes to a source generator in another project. A `dotnet build-server shutdown` at the command line resets the build-server cache and forces the generators to re-run from scratch.
Wrt. to nullable, I typically wrap generated code in `#nullable annotation`/`#nullable restore`. Then I do not have to use the damn-it operator in the generated code.
You can modify source code with Roslyn Code Generator that writes interceptors.
....sort of. You can intercept method invocations, but you can't change method bodies. Also, AFAIK, interceptors are still an experimental feature, so I didn't want to get into that in the talk - I had to enough to cover as-is :)
Starts at about 3:56
Start at 5:30
hi