MelGrubb / BuilderGenerator

A source-generator-based implementation of the Builder pattern
https://melgrubb.github.io/BuilderGenerator/
MIT License
36 stars 8 forks source link

Support custom templates #32

Open MelGrubb opened 1 year ago

MelGrubb commented 1 year ago

Make use of an assembly-level attribute to override higher-level items like the base class template, or to override templates on a global basis.

Consider allowing attribute parameters to override individual templates so that you could have multiple, alternative versions of certain templates, some of which get used for some classes, and some of which get used for others. I'm not sure this is as immediately useful, though. Interesting, but probably not worthwhile.

MelGrubb commented 8 months ago

There's a conceptual problem preventing this from moving forward. The only place to specify the version of the templates you want to use would be in the attribute. What if you tagged up different classes with different template versions? Who would win? On the surface, it seems like this would be great, you could use different templates for different classes if you wanted to, but what about the shared classes like the base class or the attribute itself? Those can only be specified once, and they will dictate the version of everything else.

For instance. C#11 allows the use of generic attributes, so we could have [BuilderFor<Foo>] instead of BuilderFor(typeof(Foo))], but that makes it incompatible with projects using previous C# versions. It might be possible to specify the template version with an assembly-level attribute. If no template is specified, then it could default to the latest version.

I'm exploring that now.