public static IRuleBuilderOptions <T, TProperty> WithLocalizedMessage <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Expression <Func <string> > resourceSelector, params Func <T, object>[] formatArgs) { // We use the StaticResourceAccessorBuilder here because we don't want calls to WithLocalizedMessage to be overriden by the ResourceProviderType. return(rule.Configure(config => { var funcs = formatArgs .Select(func => new Func <object, object, object>((instance, value) => func((T)instance))).ToList(); config.CurrentValidator.ErrorMessageSource = new BackwardsCompatFormatArgStringSource(LocalizedStringSource.CreateFromExpression(resourceSelector, null), funcs);; })); }
protected PropertyValidator(Expression <Func <string> > errorMessageResourceSelector) { originalErrorSource = errorSource = LocalizedStringSource.CreateFromExpression(errorMessageResourceSelector, new FallbackAwareResourceAccessorBuilder()); }
public string GetLocalizedString(uint val) { return(LocalizedStringSource != null?LocalizedStringSource.GetLocalizedString(val) : null); }