title: How to create a custom FluentValidation PropertyValidator with specific validation error messages?
body: <p>I have several different classes with a Name property of type <code>string</code>, but the rules for validating the name in each case are the same, e.g. must not be null, between 1 and 32 characters, must not contain certain invalid/symbol characters etc. - you get the idea.</p>
  
  <p>I am using the FluentValidation library for my validation.  I am very new to it, but like what I've seen so far.  I started by creating <code>AbstractValidator&lt;T&gt;</code> derived validation classes for each class in my object model to validate their properties.  I quickly realized that I was duplicating code to validate the Name properties of the various classes, so decided to create a <code>NameValidator</code> custom property validator (i.e. custom <code>PropertyValidator</code> derived class).  The intent was to encapsulate the four or five pieces of repetitive name validation logic in one place.</p>
  
  <p>What I don't like about this solution however (based on my novice understanding) is that I can't specify a different, specific validation error message based on the criteria for which validation fails because the error message has to be defined in the constructor and passed on to the base class.  In other words, the validation error message is tied to the class type, not the runtime logic within the <code>IsValid(...)</code> override.  For example, if the name is too long, I'd like to provide a specific message saying as such, not a compound message that says validation failed for one of a dozen different possible reasons and let the user figure out which one was the real culprit.  Perhaps this is possible somehow and I'm just missing it, or perhaps a property validator is simply not intended to support the notion of multiple types of validation.</p>
  
  <p>The next approach I considered was to create a <code>NameValidator</code> class that derives from <code>AbstractValidator&lt;string&gt;</code> and uses various <code>RuleFor</code> statements of the form: <code>RuleFor(name =&gt; name).Foo(...)</code> etc. which facilitates defining specific validation error messages.  However, this "feels wrong" because <code>AbstractValidator&lt;T&gt;</code> is intended for validating an object whereas <code>PropertyValidator</code> is intended for validating properties.  Any thoughts/advice on the validity (or otherwise) of this approach would be appreciated.</p>
  
  <p>So my question is what is the recommended way of encapsulating various pieces of property validation logic together in a reusable way using the FluentValidation library, while maintaining the ability to provide very specific validation error messages describing precisely why something failed validation?</p>