Skip to content

Commit

Permalink
validation readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pimbrouwers committed Aug 30, 2024
1 parent 6199eb6 commit 80c1310
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Danom.Validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ using FluentValidation;
public record Attendee(
string Name,
int Age,
Option<string> EmailAddress);
Option<string> Email,
Option<string> AlternateEmail);

public class AttendeeValidator
: AbstractValidator<Attendee>
Expand All @@ -36,14 +37,16 @@ public class AttendeeValidator
{
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.Age).GreaterThan(0);
RuleFor(x => x.EmailAddress).WhenSome(x => x.EmailAddress());
RuleFor(x => x.Email).Required(x => x.EmailAddress());
RuleFor(x => x.AlternateEmail).Optional(x => x.EmailAddress());
}
}
var input =
new Attendee(
Name: "John Doe",
Age: 30,
EmailAddress: Option<string>.None());
Email: Option<string>.Some("[email protected]"),
AlternateEmail: Option<string>.None());

var result =
ValidationResult<Attendee>
Expand Down

0 comments on commit 80c1310

Please sign in to comment.