Created
December 21, 2010 11:48
-
-
Save JeremySkinner/749837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Should allow for this syntax: | |
| // RuleFor(x => x.Surname).NotNull().WithLocalizedMessage(() => MyResources.SomeResource, x => "foo", x => "bar"); | |
| // ...where MyResources.SomeResource has format placeholders | |
| public static IRuleBuilderOptions<T, TProperty> WithLocalizedMessage<T, TProperty>(this IRuleBuilderOptions<T, TProperty> rule, Expression<Func<string>> resourceSelector, params Func<T, object>[] funcs) { | |
| return rule.Configure(config => { | |
| config.CurrentValidator.ErrorMessageSource = LocalizedStringSource.CreateFromExpression(resourceSelector, new StaticResourceAccessorBuilder()); | |
| funcs | |
| .Select(func => new Func<object, object>(x => func((T)x))) | |
| .ForEach(config.CurrentValidator.CustomMessageFormatArguments.Add); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment