Add optional "interval notation" argument to ValueObjectAttribute for easy range validation #866
prlcutting
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Vogen supports custom validation, which is great. But this can be a little repetitive and "boilerplatey" for numeric value objects that require basic range checks, e.g., "value must greater than or equal to zero", or "value cannot exceed 100", etc.
I was wondering if this could be streamlined by the definition of some kind of range validation argument on the
ValueObjectAttributeusing interval notation:Interval notation provides a very compact, terse way of expressing min/max values, and whether those values are inclusive/exclusive.
Here are some examples of sample usage (pseudocode):
This would of course source generate the same kind of validation code that I would have otherwise had to define manually, and is the value of this proposal: as a developer I get to define range validation through a terse interval notation, and then all the code to enforce that validation is source generated for me.
Consideration would have to be given as to exactly how this is done, e.g., does it literally write the
Validatemethod for me, and if so, if additional validation was required beyond just range checking, how would that be added, etc. But those are details, and this is clearly far from a design spec, rather, just an initial idea for consideration.The same concept could perhaps also be used for strings to succinctly express length constraints, e.g.:
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions