views:

201

answers:

1

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?

+1  A: 

It is still possible to write custom attribute.

Bystrik Jurina
Old question... going for a Necromancer badge? :) Ultimately I worked around this issue by doing as you suggest. Then we ended up scrapping VAB and using DataAnnotations.
Sailing Judo
I'll give you the answer anyway as nobody else even made an effort to help when I needed it.
Sailing Judo