How to create custom ValueObjectAttribute attributes with my own defaults and custom properties? #903
Replies: 2 comments
-
|
Hi, thanks for the feedback. It's unfortunate that this isn't possible as it'd be invaluable! My time is quite limited so it's unlikely I can spend the time necessary for this to be fixed in a way that doesn't impact performance of the source generator. |
Beta Was this translation helpful? Give feedback.
-
|
Hi Steve. Thanks for the reply to my questions and clarifying a few things for me. Do you recall, was the source-generation performance issue related to needing to discover all attributes, and then checking if any of them derive from |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Sadly, it seems that this used to be possible, but not now, according to the documentation:
But I find myself with exactly this need. I attempted to create a custom
ValueObjectAttribute-derived attribute class and pass down to the base class my preferred configuration defaults. But Vogen didn't honor it. That seems consistent with the early part of the documentation (which I only discovered after the fact), however, the last part of the documentation seems to suggest doing exactly what I did. I'm a bit confused. Also, how does "using the type alias feature" help here? If anybody could enlighten me on this, it would be much appreciated!I have resorted to creating my own non-
ValueObjectAttribute-derived marker attribute (along with some new, custom properties) and source generating another portion of the partial struct alongside what Vogen source generates. In other words, my VOs have two attributes applied to them: the Vogen one, and my custom one. But this is far from smooth. The DX isn't as nice (two attributes to achieve one goal rather than one). A separate issue perhaps, but things like overridingToStringetc. don't work, as Vogen is blissfully unaware of my own source generation, and as such, two duplicateToStringimplementations get source generated, which of course results in a compilation error. I have dozens of VOs that I would like to create with the same customToStringimplementation, and repeating it on each one to prevent Vogen from generating its default implementation seems unfortunate. An option to disable aToStringgeneration might be a helpful workaround. BTW... I'm creatingstruct-based VOs, so a base class isn't an option.Beta Was this translation helpful? Give feedback.
All reactions