-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make defaultable values validatable #51
Comments
Hi @dzmitry-lahoda - visiting some old comments now that I've got a bit of time free. Do you mean to make the generated code |
yes, so it will depend on componentmodel. and may be using validation attributes support on ctor parameters us enough. so that when error is raised it looks noce in xaml or api. |
Hi @dzmitry-lahoda , I'm taking a quick look at this one again.
Vogen deliberately doesn't have constructors. Do you expect it to look something like this: [ValueObject<int>]
public partial class CustomerId : IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if(Value is < 1 or > 100)
yield return new ValidationResult("Value must be between 1 and 100.", new[] { "Value" });
}
} With this, Vogen still won't know whether it's valid. So do you propose that when creating an instance, e.g: var id = CustomerId.From(123); That Vogen generates the code to call your ... or, are you proposing that [ValueObject<int>]
public partial class Whatever : IValidatableObject
{
private static Validation Validate(int v)
{
if (v is < 1 or > 100) return Validation.Invalid("Value must be between 1 and 100");
return Validation.Ok;
}
// THIS METHOD IS AUTO GENERATED BY VOGEN
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
Validation result = Validate(Value);
if(result == Validation.Ok) yield break;
yield return new ValidationResult(result.ErrorMessage);
}
} |
Yes. Parse do not validate. |
https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.ivalidatableobject.validate .
The text was updated successfully, but these errors were encountered: