.netvalidationapplication-blocks

Is there a way to supply a default MessageTemplateResourceType to a Validator?


I have a class with lots of string properties that need validated. I'm using the Validation Application Block because I'm a big fan of using attributes to solve this kind of need. Everything works great but my manager isn't a fan of the amount of code needed in implementing the Message Template Tokens and resource file.

For example:

 [StringLengthValidator(100, 
        MessageTemplateResourceName = "InvalidStringLengthMessage", 
        MessageTemplateResourceType = typeof(Xltech.Common.Resources.XLStrings))]
 public string FirstName {get; set;}

The issue is that every argument after the 100 (the maximum string length) is the same for every StringLengthValidator we have in this class (actually, for the entire solution).

Is there a way to at least give the validators a common MessageTemplateResourceType so I can reduce the copy/pasting involved?


Solution

  • It is still possible to write custom attribute.