ValidatorResult IValidator.Check(object value, ValidatorContext context) { if (value != null && !(value is TValue)) { throw new ArgumentException("Invalid value type", nameof(value)); } return(GetValidationExpression(context).Compile()((TValue)value)); }
string IValidator.BuildJS(ValidatorContext context) { return($"v => ({GetValidationExpression(context).ToJs()})(v) || {JsonConvert.SerializeObject(ErrorMessage)}"); }
protected abstract Expression <Func <TValue, ValidatorResult> > GetValidationExpression(ValidatorContext context);
public ValidatorResult Check(object value, ValidatorContext context) { return(Check(value, context, context.Attribute <TAttribute>())); }
protected abstract ValidatorResult Check(object value, ValidatorContext context, TAttribute attribute);
public string BuildJS(ValidatorContext context) { return(BuildJS(context, context.Attribute <TAttribute>())); }
protected abstract string BuildJS(ValidatorContext context, TAttribute attribute);