c# 4.0 - Can I use mutiple RuleSet withe in a same Validator Attribute in Microsoft Enterprise Library Validation Framework -


helllo..... quite new in microsoft enterprise library validation framework. question want same validation condition in 2 different ruleset. possible put 2 rule set in same validator below

/// <summary> ///  /// </summary> [stringlengthvalidator(1,25,ruleset="detailruleset",ruleset="mainruleset",tag="first name")] public string firstname {     { return firstname; }     set { firstname = value; } } 

or have mentioned writing same in 2 time different ruleset name below

    /// <summary>     ///      /// </summary>     [stringlengthvalidator(1,25,ruleset="detailruleset",tag="first name")]     [stringlengthvalidator(1, 25, ruleset = "mainruleset", tag = "first name")]     public string firstname     {         { return firstname; }         set { firstname = value; }     } 

any appreciated!!

first disclaimer: haven't worked on enterprise library application validation block, however, having been programmer on decade , half, , having used validation models asp.net mvc data annotations, can tell api validation in enterprise library pretty similar. took me 20 minutes download enterprise library source code , answer question. so, here's answer.

yes, can apply more 1 validation attribute given model property, each validation attribute specifying different rule set.

however, in such case, have explicitly invoke validator on model type particular rule set.

if not that, enterprise library execute validator default rule-set.

in context of example, can say:

stringlengthvalidator(1,25,ruleset="detailruleset",tag="first name")]     [stringlengthvalidator(1, 25, ruleset = "mainruleset", tag = "first name")]     public string firstname     {         { return firstname; }         set { firstname = value; }     } 

however, in case, have invoke 1 of rule-sets validation, so:

var yourmodelobjectvalidator =      yourvalidatorfactory.createvalidator<yourmodelclass>("yourrulesetname");  var yourmodelobject =      new yourmodelclass { foo = "foo", bar = "bar", gar = 2 };  var results =      yourmodelobjectvalidator.validate(yourmodelobject);  if (!results.isvalid) {    foreach(var result in results)      {          /* run state machine, whatever, print */      } } 

if not specify rule set name did above, enterprise library execute validations in context of default rule set has no name, , hence none of 2 rules specified above using validation attributes executed.

update

based on comment, see real question is.

your question is: can specify more single rule-set in single validation attribute declaration?

the answer simple question: no. because property ruleset declared string , not ienumerable<string> in basevalidationattribute class, mother of validatorattribute classes in entlib source code.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -