Example #1
0
        public static RuleMethod CreateRuleMethod(Type pTargetType, string pPropertyName, object pMissingValue)
        {
            PropertyRequiredRuleArgs args =
                new PropertyRequiredRuleArgs(pTargetType, pPropertyName);
            RuleMethod rule = new RuleMethod(PropertyRequiredHandler, args);

            return(rule);
        }
Example #2
0
        private void CheckRuleX(RuleMethod pRule)
        {
            bool passed = pRule.Invoke(mTarget);

            if (passed)
            {
                BrokenRulesX.Remove(pRule.RuleName);
            }
            else
            {
                BrokenRulesX.Add(pRule);
            }
        }
Example #3
0
 /// <summary>Check a particular RuleMethod.</summary>
 public void CheckRule(RuleMethod rule)
 {
     if (!Enabled)
     {
         return;
     }
     if (rule is MultiPropertyRuleMethod)
     {
         CheckMultiPropertyRuleX((MultiPropertyRuleMethod)rule);
     }
     else
     {
         CheckRuleX(rule);
     }
 }
Example #4
0
        /// <summary>Creates and adds a RuleMethod to the list of rules to be enforced.</summary>
        /// <param name="pHandler">The handler that implements the rule. Should be a static delegate.</param>
        /// <param name="pPropertyName">The property name of the target type,
        /// where the rule implementation can retrievethe value to be validated.
        /// </param>
        /// <returns>The added RuleMethod.</returns>
        /// <remarks>
        /// <para>
        /// A rule is implemented by a method which conforms to the
        /// method signature defined by the RuleHandler delegate.
        /// </para><para>
        /// The propertyName may be used by the method that implements the rule
        /// in order to retrieve the value to be validated.
        /// </para><para>
        /// If the rule implementation is inside the target object class then it probably has
        /// direct access to all data (even though the handler is a static delegate).
        /// If the rule implementation is outside the target class
        /// then it will need to use reflection to dynamically invoke this property to retrieve
        /// the value to be validated.
        /// </para>
        /// </remarks>
        public RuleMethod Add(RuleHandler pHandler, string pPropertyName)
        {
            RuleMethod method = new RuleMethod(pHandler, pPropertyName);

            return(AddX(pPropertyName, method));
        }
Example #5
0
 /// <summary>Remove a specific rule from the rule list.</summary>
 public void Remove(RuleMethod pMethod)
 {
     Remove(pMethod.RuleHandler, pMethod.RuleArgs);
 }
Example #6
0
 private RuleMethod AddX(string pPropertyName, RuleMethod pMethod)
 {
     GetRulesForProperty(pPropertyName).Add(pMethod);
     return(pMethod);
 }
Example #7
0
 /// <summary>Adds the RuleMethod to the list of rules to be enforced.</summary>
 /// <param name="pMethod">The RuleMethod that implements the rule.</param>
 /// <returns>The added RuleMethod.</returns>
 /// <remarks>
 /// A rule is implemented by a method which conforms to the
 /// method signature defined by the RuleHandler delegate.
 /// </remarks>
 public RuleMethod Add(RuleMethod pMethod)
 {
     return(AddX(pMethod.RuleArgs.PropertyName, pMethod));
 }
Example #8
0
        /// <summary>Creates and adds a RuleMethod to the list of rules to be enforced.</summary>
        /// <param name="pHandler">The handler that implements the rule. Should be a static delegate.</param>
        /// <param name="args">
        /// A RuleArgs object specifying the property name (or group name) and other arguments
        /// passed to the rule method</param>
        /// <returns>The added RuleMethod.</returns>
        /// <remarks>
        /// A rule is implemented by a delegate which conforms to the
        /// method signature defined by the RuleHandler delegate.
        /// </remarks>
        public RuleMethod Add(RuleHandler pHandler, RuleArgs args)
        {
            RuleMethod method = new RuleMethod(pHandler, args);

            return(AddX(args.PropertyName, method));
        }
Example #9
0
 internal BrokenRule(RuleMethod rule)
     : this(rule.RuleName, rule.RuleArgs.Description, rule.RuleArgs.PropertyName, null)
 {
 }
Example #10
0
        public static RuleMethod Add(RuleList pRuleList, string pPropertyName)
        {
            RuleMethod rule = CreateRuleMethod(pRuleList.TargetType, pPropertyName);

            return(pRuleList.Add(rule));
        }
Example #11
0
 /// <summary>Create BrokenRule from this RuleMethod and add it to the collection .</summary>
 /// <remarks>Removes any previous version of this rule first.</remarks>
 internal void Add(RuleMethod pRule)
 {
     Remove(pRule.RuleName);
     Add(new BrokenRule(pRule));
 }