To clarify, I mean writing scripts that generate or modify classes for you instead of manually writing them every time, for example if you want to replace reflection with a ton of verbose repetitive code for performance reasons I guess?

My only experience with this is just plain old manual txt generation with something like python, and maintaining legacy t4/tt VS files but those are kind of a nightmare.

What’s a good modern way of accomplishing this, have there been any improvements in this area?

  •  TehPers   ( @TehPers@beehaw.org ) 
    link
    fedilink
    English
    33 months ago

    If you’re writing C#, you could take a look into Source Generators. They’re supported directly by Roslyn I believe, and are pure C# instead of t4’s syntax. They’re often used with attributes to augment types, but I believe they can be used to generate sources on their own, and even read from a config file if you want to (or maybe even query the DB, if that’s something you want to do at build time for some reason, though I’ve never tried this).