Add support for validation
desarrollo03TR opened this issue · 1 comments
desarrollo03TR commented
I love the tool, but IMHO it could be better if we can validate the value. For example, I want a ">=0" id, and throw an exception if a negative value is created.
Thanks!
vbfox commented
Hi,
this is already supported with a partial member called CheckValue
that is called at the end of the constructor, it can be used like that :
public partial struct Id
{
partial void CheckValue(int value)
{
if (value <= 0)
{
throw new Exception("Boom");
}
}
One thing to note is that the types being structs, the value generated by default(Id)
can always be created (I never had the need to make them classes to close this small loophole but I would accept a PR for a setting doing that)