public EqualValidator(Func <object, object> comparisonProperty, MemberInfo member) : base(nameof(Messages.equal_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Equal); func = comparisonProperty; MemberToCompare = member; }
public EqualValidator(object valueToCompare, IEqualityComparer comparer) : base(nameof(Messages.equal_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Equal); ValueToCompare = valueToCompare; this.comparer = comparer; }
public UserHasCorrectValidator(IEnumerable <string> role, IMediator mediator) : base(new StaticStringSource("")) { this.role = role; this.mediator = mediator; ErrorCodeSource = new StaticStringSource(nameof(UserHasCorrectValidator)); }
protected override bool IsValid(PropertyValidatorContext context) { var establishmentId = _establishmentId((T)context.Instance); var principalOrPersonId = context.PropertyValue; var principal = principalOrPersonId as IPrincipal; var personId = principal != null ? 0 : (int)principalOrPersonId; if (personId == 0) { personId = _queryProcessor.Execute(new MyPerson(principal)).RevisionId; } var entity = _queryProcessor.Execute(new AffiliationByPrimaryKey(personId, establishmentId)); if (entity != null) { return(true); } if (principal != null) { ErrorMessageSource = new StaticStringSource(PrincipalFailMessageFormat); context.MessageFormatter.AppendArgument("PropertyValue", principal.Identity.Name); } else { ErrorMessageSource = new StaticStringSource(PersonFailMessageFormat); context.MessageFormatter.AppendArgument("PropertyValue", personId); } context.MessageFormatter.AppendArgument("EstablishmentId", establishmentId); return(false); }
public NotEqualValidator(object comparisonValue, IEqualityComparer equalityComparer) : base(nameof(Messages.notequal_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.NotEqual); ValueToCompare = comparisonValue; comparer = equalityComparer; }
public NotEqualValidator(Func <object, object> func, MemberInfo memberToCompare) : base(nameof(Messages.notequal_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.NotEqual); this.func = func; MemberToCompare = memberToCompare; }
public RegularExpressionValidator(string expression, RegexOptions options) : base(nameof(Messages.regex_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.RegularExpression); this.expression = expression; var regex = new Regex(expression, options); this.regexFunc = x => regex; }
protected PropertyValidator(IStringSource errorMessageSource) { if (errorMessageSource == null) { errorMessageSource = new StaticStringSource("No default error message has been specified."); } errorSource = errorMessageSource; }
public InclusiveBetweenValidator(IComparable from, IComparable to) : base(nameof(Messages.inclusivebetween_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.InclusiveBetween); To = to; From = from; if (Comparer.GetComparisonResult(to, from) == -1) { throw new ArgumentOutOfRangeException("to", "To should be larger than from."); } }
public LengthValidator(int min, int max, string resourceName, Type resourceType) : base(resourceName, resourceType) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Length); Max = max; Min = min; if (max != -1 && max < min) { throw new ArgumentOutOfRangeException("max", "Max should be larger than min."); } }
protected PropertyValidator(IStringSource errorMessageSource) { if (errorMessageSource == null) { errorMessageSource = new StaticStringSource("No default error message has been specified."); } else if (errorMessageSource is LanguageStringSource l) { errorMessageSource = new ErrorCodeLanguageStringSource(ctx => Options.ErrorCodeSource?.GetString(ctx), l); } Options.ErrorMessageSource = errorMessageSource; }
protected PropertyValidator(IStringSource errorMessageSource) { if (errorMessageSource == null) { errorMessageSource = new StaticStringSource("No default error message has been specified."); } else if (errorMessageSource is LanguageStringSource l && l.ErrorCodeFunc == null) { l.ErrorCodeFunc = ctx => ErrorCodeSource?.GetString(ctx); } ErrorMessageSource = errorMessageSource; }
/// <summary> /// Creates a new property rule. /// </summary> /// <param name="member">Property</param> /// <param name="propertyFunc">Function to get the property value</param> /// <param name="expression">Lambda expression used to create the rule</param> /// <param name="cascadeModeThunk">Function to get the cascade mode.</param> /// <param name="typeToValidate">Type to validate</param> /// <param name="containerType">Container type that owns the property</param> public PropertyRule(MemberInfo member, Func <object, object> propertyFunc, LambdaExpression expression, Func <CascadeMode> cascadeModeThunk, Type typeToValidate, Type containerType) { Member = member; PropertyFunc = propertyFunc; Expression = expression; OnFailure = x => { }; TypeToValidate = typeToValidate; this.cascadeModeThunk = cascadeModeThunk; PropertyName = ValidatorOptions.PropertyNameResolver(containerType, member, expression); string displayName = ValidatorOptions.DisplayNameResolver(containerType, member, expression); if (!string.IsNullOrEmpty(displayName)) { DisplayName = new StaticStringSource(displayName); } }
protected override bool IsValid(PropertyValidatorContext context) { var establishmentId = _establishmentId((T)context.Instance); var principalOrPersonId = context.PropertyValue; var principal = principalOrPersonId as IPrincipal; var personId = principal != null ? 0 : (int)principalOrPersonId; var eagerLoad = new Expression <Func <Person, object> >[] { x => x.Affiliations.Select(y => y.Establishment.Offspring), }; var person = principal != null ? _queryProcessor.Execute(new MyPerson(principal) { EagerLoad = eagerLoad, }) : _queryProcessor.Execute(new PersonById(personId) { EagerLoad = eagerLoad, }); var offspringOfDefault = person.DefaultAffiliation != null ? person.DefaultAffiliation.Establishment.Offspring.FirstOrDefault(x => x.OffspringId == establishmentId) : null; if (offspringOfDefault != null) { return(true); } if (principal != null) { ErrorMessageSource = new StaticStringSource(PrincipalFailMessageFormat); context.MessageFormatter.AppendArgument("PropertyValue", principal.Identity.Name); } else { ErrorMessageSource = new StaticStringSource(PersonFailMessageFormat); context.MessageFormatter.AppendArgument("PropertyValue", personId); } context.MessageFormatter.AppendArgument("EstablishmentId", establishmentId); return(false); }
private void Init(int scale, int precision) { ErrorCodeSource = new StaticStringSource(ValidationErrors.ScalePrecision); Scale = scale; Precision = precision; if (Scale < 0) { throw new ArgumentOutOfRangeException( "scale", string.Format("Scale must be a positive integer. [value:{0}].", Scale)); } if (Precision < 0) { throw new ArgumentOutOfRangeException( "precision", string.Format("Precision must be a positive integer. [value:{0}].", Precision)); } if (Precision < Scale) { throw new ArgumentOutOfRangeException( "scale", string.Format("Scale must be less than precision. [scale:{0}, precision:{1}].", Scale, Precision)); } }
public NullValidator() : base(nameof(Messages.null_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Null); }
public LengthValidator(Func <object, int> min, Func <object, int> max, string resourceName, Type resourceType) : base(resourceName, resourceType) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Length); MaxFunc = max; MinFunc = min; }
public EmailValidator() : base(nameof(Messages.email_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Email); regex = new Regex(expression, RegexOptions.IgnoreCase); }
public IsValidUserValidator(IMediator mediator) : base(new StaticStringSource("")) { this.mediator = mediator; ErrorCodeSource = new StaticStringSource(nameof(IsValidUserValidator)); }
public EmptyValidator(object defaultValueForType) : base(nameof(Messages.empty_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Empty); this.defaultValueForType = defaultValueForType; }
public EnumValidator(Type enumType) : base(nameof(Messages.enum_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Enum); this.enumType = enumType; }
public ExactLengthValidator(int length) : base(length, length, nameof(Messages.exact_length_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Length); }
public LessThanOrEqualValidator(IComparable value) : base(value, nameof(Messages.lessthanorequal_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.LessThanOrEqual); }
public RegularExpressionValidator(Func <object, string> expression, RegexOptions options) : base(nameof(Messages.regex_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.RegularExpression); this.regexFunc = x => new Regex(expression(x), options); }
public GreaterThanValidator(Func <object, object> valueToCompareFunc, MemberInfo member) : base(valueToCompareFunc, member, nameof(Messages.greaterthan_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.GreaterThan); }
public PredicateValidator(Predicate predicate) : base(nameof(Messages.predicate_error), typeof(Messages)) { predicate.Guard("A predicate must be specified."); ErrorCodeSource = new StaticStringSource(ValidationErrors.Predicate); this.predicate = predicate; }
// This logic was taken from the CreditCardAttribute in the ASP.NET MVC3 source. public CreditCardValidator() : base(nameof(Messages.CreditCardError), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.CreditCard); }
public LessThanOrEqualValidator(Func <object, object> valueToCompareFunc, MemberInfo member) : base(valueToCompareFunc, member, nameof(Messages.lessthanorequal_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.LessThanOrEqual); }
public GreaterThanValidator(IComparable value) : base(value, nameof(Messages.greaterthan_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.GreaterThan); }
public LengthValidator(int min, int max) : this(min, max, nameof(Messages.length_error), typeof(Messages)) { ErrorCodeSource = new StaticStringSource(ValidationErrors.Length); }