コード例 #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Birthdate > DateTimeOffset.Now)
            {
                yield return(new ValidationResult("A person cannot be born in the future.", new string[] { nameof(Birthdate) }));
            }

            if (EmailAddresses.GroupBy(e => e.Email).Select(grp => grp.Count()).Any(c => c > 1))
            {
                yield return(new ValidationResult("Email addresses must be unique.", new string[] { nameof(EmailAddresses) }));
            }
        }