On .NET Live: Lessons Learned Building Source Generators

Поділитися
Вставка
  • Опубліковано 10 лип 2024
  • C# code generators are tools that automatically create source code based on predefined templates or rules. In this week's episode, community MVP Jason Bock returns to show us lessons he's learned about what works, what doesn't, and what developers should avoid!
    ⌚ Chapters:
    00:00 Countdown begins
    03:12 Welcome to On .NET Live
    03:57 Jason Bock intro
    06:48 Source Generators - overview
    11:12 Demo - lessons learned
    57:00 In summary
    59:21 Wrap
    Resources:
    Blog:
    devblogs.microsoft.com/dotnet...
    Source Generators Docs:
    learn.microsoft.com/en-us/dot...
    Jason's Repo: github.com/JasonBock/Rocks
    Benchmark Mock Net Repo:
    github.com/ecoAPM/BenchmarkMo...
    Incremental Generators Repo:
    github.com/dotnet/roslyn/blob...
    Null Safety Docs:
    learn.microsoft.com/en-us/tra...
    Featuring: Jason Bock, Frank Boucher, David Pine (@davidpine7), Cam Soper
    #code-generators
  • Наука та технологія

КОМЕНТАРІ • 7

  • @NotInventedHereShow
    @NotInventedHereShow 3 місяці тому +2

    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.

  • @daniloa.1455
    @daniloa.1455 Місяць тому +1

    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"

  • @VOXindie
    @VOXindie 3 місяці тому

    Start at 5:30

  • @IgnatAndrei
    @IgnatAndrei 3 місяці тому +1

    You can modify source code with Roslyn Code Generator that writes interceptors.

    • @JasonBock
      @JasonBock 3 місяці тому +1

      ....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 :)

  • @StephenJWalter
    @StephenJWalter 3 місяці тому

    Starts at about 3:56

  • @ilayarajag6064
    @ilayarajag6064 3 місяці тому

    hi