Skip to content

Instantly share code, notes, and snippets.

@JeremySkinner
Last active June 19, 2018 11:03
Show Gist options
  • Save JeremySkinner/c5548a477206ea7f66639fc5ba9d099f to your computer and use it in GitHub Desktop.
Save JeremySkinner/c5548a477206ea7f66639fc5ba9d099f to your computer and use it in GitHub Desktop.
Message builder example
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