The LocalizedDisplayName works well if your solution allows you to work with resource strings. unfortunately in my project we have several languages and growing... and the translations are all maintained in the database.
We have therefore taken the approach to
- inherit from the attribute in our own dll, and
- then get the default format string and use that as a base value for our messages
- have our translation factory get the value or register the default in the database
then we import the namespace and give it an alias, the implemented version looks something like this:
using tf = MyDating.Translation;
in the ViewViewModel we do:
[tf.DisplayName("Verify Password")]
[DataType(DataType.Password)]
[tf.Compare("Password")]
public string VerifyPassword
{
get;
set;
}
the above CompareAttribute then looks something like this:
public class CompareAttribute : System.ComponentModel.DataAnnotations.CompareAttribute
{
public CompareAttribute(string otherProperty)
:base(otherProperty)
{
var tf = TranslatetionFactory.Current.GetSection("CompareAttribute");
var msg = tf.Get(this.ErrorMessageString);
ErrorMessage = msg;
}
}