WFXmlRuleSetProvider

This class is used to provide validation rules that have already been determined from an XML validation configuration.

Use WFUtilities.RegisterXMLValidationConfiguration() to register an XML configuration file. This can be done in Global.asax.cs in Application_Start as this only need happen once.

Constructors
  • WFXmlRuleSetProvider(XmlDataAnnotationsRuleSet ruleSet)
Initializes a new instance of the WFXmlRuleSetProvider class using ruleSet to provide the validation rules.
  • WFXmlRuleSetProvider(string ruleSetName)
Initializes a new instance of the WFXmlRuleSetProvider class and uses the WFUtilities.GetRuleSetForName() method to determine the rule set to provide validation rules.

Interface Implementations
  • IWFRuleProvider.ValidationType
Gets or set the type rules have been derived from. Setting the type will not trigger a refresh of the validation rules.
  • IWFRuleProvider.GetClassValidationAttributes
Used when validation takes place. This will return any validation rules applied directly to the class. In the following example this is represented by the <validator> tag.
<validation>
   <type assemblyName="MyAssembly" name="MyAssembly.ClassName, MyAssembly">
      <ruleset name="MyRuleSet">
         <attributes>
            <validator ...></validator>
  • IWFRuleProvider.GetPropertyValidationAttributes(string propertyName)
Used when validation takes place. This will return any validation rules applied to a Property whose name matches propertyName. It is case-insensitive.
If no property matches, an empty collection of ValidationAttribute is returned. In the following example this is represented by the <validator> tag.
<validation>
   <type assemblyName="MyAssembly" name="MyAssembly.ClassName, MyAssembly">
      <ruleset name="MyRuleSet">
         <properties>
            <property name="MyProperty">
               <validator ... />
  • IWFRuleProvider.GetDisplayNameForProperty(string propertyName)
If the XML configuration defines a DisplayName attribute on the property node, it will be used as the DisplayName. Otherwise if a DisplayNameResourceName and DisplayNameResourceType are specified, they will be used to lookup the globalized Resources file to determine the DisplayName. If none of these are specified, the DisplayName will be empty.
<validation>
   <type assemblyName="MyAssembly" name="MyAssembly.ClassName, MyAssembly">
      <ruleset name="MyRuleSet">
         <properties>
            <property name="MyProperty" DisplayName="MyDisplayName" ... >
               ...
<validation>
   <type assemblyName="MyAssembly" name="MyAssembly.ClassName, MyAssembly">
      <ruleset name="MyRuleSet">
         <properties>
            <property name="MyProperty" 
                             DisplayNameResourceName="MyPropertyDisplayName"
                             DisplayNameResourceType="MyAssembly.Properties.Resources, MyAssembly" ... >
               ...
  • IWFRuleProvider.ModelDisplayName
Get or set the display name of the type used to provide validation rules. If "DisplayName" is not present, the name will be empty.
This is represented by the string "MyDisplayName" in the following example.
<validation>
   <type assemblyName="MyAssembly" name="MyAssembly.ClassName, MyAssembly">
      <ruleset name="MyRuleSet" DisplayName="MyDisplayName">

Last edited May 19, 2012 at 9:28 PM by aikeru, version 4

Comments

No comments yet.