Dynamic validation messages

Dec 10, 2013 at 4:52 PM
Edited Dec 10, 2013 at 4:53 PM
I'm switching to SpecExpress from Fluent Validation and I'm having trouble with putting dynamic data in custom messages. I understand how to use With() to get a custom message (including the ability to use { PropertyValue } ), but I can't find a way to include other object properties in the validation message.

For example, Fluent Validation allows this:
//Referencing other property values:
RuleFor(customer => customer.Surname)
  .WithMesasge("This message references some other properties: Forename: {0} Discount: {1}", 
    customer => customer.Forename, 
    customer => customer.Discount
//Result would be: "This message references some other properties: Forename: Jeremy Discount: 100"
Are there plans for SpecExpress to have a similar feature or is it there already?

Thanks for your time and help and a great product.
Dec 12, 2013 at 2:42 PM
The current release doesn't support this functionality. But after looking a little deeper, it wasn't that hard to add. I don't have a build for it, but you can jump out to GitHub, grab the FormatMessage Branch, and build it yourself to get this functionality.

You can use it like this:
Check(customer => customer.Surname).Required()
    .With( m => m.MessageFormat("This message references some other properties: Forename: {0} Discount: {1}", customer.Forename, customer.Discount));
Let me know if you have any issues.