Last active
June 19, 2018 11:03
-
-
Save JeremySkinner/c5548a477206ea7f66639fc5ba9d099f to your computer and use it in GitHub Desktop.
Message builder example
This file contains 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
public static class Extensions { | |
public static IRuleBuilderOptions<T, TProperty> Prefix<T, TProperty>(this IRuleBuilderOptions<T, TProperty> rule, string prefix) { | |
return rule.Configure(cfg => { | |
cfg.MessageBuilder = context => { | |
// The MessageBuilderContext has lots of useful things on it, see https://github.com/JeremySkinner/FluentValidation/blob/master/src/FluentValidation/Internal/MessageBuilderContext.cs | |
return prefix + " " + context.GetDefaultMessage(); | |
}; | |
}); | |
} | |
// Usable like so: | |
RuleFor(x => x.Surname).NotNull().Prefix("Foo"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment