예제 #1
0
 /// <summary>Creates and initializes the rule.</summary>
 /// <param name="pHandler">The address of the method implementing the rule.</param>
 /// <param name="pArgs">A RuleArgs object.</param>
 /// <param name="pPropertyNames">The fields, properties or columns to which the rule applies.</param>
 public MultiPropertyRuleMethod(RuleHandler pHandler, RuleArgs pArgs, params string[] pPropertyNames)
     : base(pHandler, pArgs)
 {
     if (pPropertyNames == null || pPropertyNames.Length < 2)
     {
         throw new ArgumentException("MultiPropertyRules require at least two properties.");
     }
     mPropertyNames = pPropertyNames;
 }
예제 #2
0
 public static bool ObjectRequired(object target, RuleArgs e)
 {
     if (null == ExtendedReflectionFns.GetPropertyValue(target, e.PropertyName))
     {
         e.Description =
             string.Format(Resources.StringRequiredRule, e.DisplayPropertyName);
         return(false);
     }
     return(true);
 }
예제 #3
0
        public static bool StringRequired(object target, RuleArgs e)
        {
            string value = (string)ExtendedReflectionFns.GetPropertyValue(target, e.PropertyName);

            if (string.IsNullOrEmpty(value))
            {
                e.Description =
                    string.Format(Resources.StringRequiredRule, e.DisplayPropertyName);
                return(false);
            }
            return(true);
        }
예제 #4
0
        public static bool StringMinLength(object target, RuleArgs e)
        {
            int    min   = ((MinMaxArgs <Int32>)e).MinValue;
            string value = (string)ExtendedReflectionFns.GetPropertyValue(target, e.PropertyName);

            if (String.IsNullOrEmpty(value) || (value.Trim().Length < min))
            {
                e.Description = String.Format(
                    Resources.StringMinLengthRule, e.DisplayPropertyName, min.ToString());
                return(false);
            }
            return(true);
        }
예제 #5
0
        public static bool StringMaxLength(object target, RuleArgs e)
        {
            int    max   = (int)((MinMaxArgs <Int32>)e).MaxValue;
            string value = (string)ExtendedReflectionFns.GetPropertyValue(target, e.PropertyName);

            if (!String.IsNullOrEmpty(value) && (value.Length > max))
            {
                e.Description = String.Format(
                    Resources.StringMaxLengthRule, e.DisplayPropertyName, max.ToString());
                return(false);
            }
            return(true);
        }
예제 #6
0
 /// <summary>Creates and initializes the rule.</summary>
 /// <param name="pHandler">The address of the method implementing the rule.</param>
 /// <param name="pArgs">Rule arguments.</param>
 /// <param name="pBusinessPropertys">The entity columns to which the rule applies.</param>
 public MultiPropertyRuleMethod(RuleHandler pHandler, RuleArgs pArgs, params BusinessProperty[] pBusinessPropertys)
     : base(pHandler, pArgs)
 {
     if (pBusinessPropertys == null || pBusinessPropertys.Length < 2)
     {
         throw new ArgumentException("MultiPropertyRules require at least two properties.");
     }
     mPropertyNames = new string[pBusinessPropertys.Length];
     for (int i = 0; i < pBusinessPropertys.Length; i++)
     {
         mPropertyNames[i] = pBusinessPropertys[i].Name;
     }
 }
예제 #7
0
        private static bool PropertyRequiredHandler(object pTarget, RuleArgs pArgs)
        {
            PropertyRequiredRuleArgs args = (PropertyRequiredRuleArgs)pArgs;
            bool ok = HasValue(pTarget, args);

            if (ok)
            {
                return(true);
            }
            args.Description =
                string.Format(Properties.Resources.StringRequiredRule, args.DisplayPropertyName);
            return(false);
        }
예제 #8
0
        /// <summary>Rule ensuring that a numeric value is not less than the specified minimum.</summary>
        /// <typeparam name="T">Type of the property to validate.</typeparam>
        /// <param name="target">Object containing value to validate.</param>
        /// <param name="e">Arguments variable specifying the name of the property to validate,
        /// along with the min allowed value.</param>
        /// <remarks>
        /// Converts the arguments to the target type, T, if it can and calls CompareTo.
        /// <para>Heavily revised by IdeaBlade.</para>
        /// </remarks>
        public static bool MinValue <T>(object target, RuleArgs e)
        {
            T      min    = (T)((MinMaxArgs <T>)e).MinValue;
            object value  = ExtendedReflectionFns.GetPropertyValue(target, e.PropertyName);
            bool   result = Compare <T>(value, min) >= 0;

            if (!result)
            {
                e.Description =
                    string.Format(Resources.MinValueRule, e.DisplayPropertyName, min.ToString());
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #9
0
        public static bool MinMaxValue <T>(object target, RuleArgs e)
        {
            T      min   = ((MinMaxArgs <T>)e).MinValue;
            T      max   = ((MinMaxArgs <T>)e).MaxValue;
            object value = ExtendedReflectionFns.GetPropertyValue(target, e.PropertyName);
            bool   ok    = true;

            if (value != null)
            {
                ok = (Compare <T>(value, min) >= 0 && Compare <T>(value, max) <= 0);
            }
            if (ok)
            {
                return(true);
            }
            e.Description = String.Format(
                Resources.BetweenRule, e.DisplayPropertyName, min.ToString(), max.ToString());
            return(false);
        }
예제 #10
0
        public static bool IntegerMinMaxValue(object target, RuleArgs e)
        {
            long   min   = ((MinMaxArgs <Int64>)e).MinValue;
            long   max   = ((MinMaxArgs <Int64>)e).MaxValue;
            object value = ExtendedReflectionFns.GetPropertyValue(target, e.PropertyName);
            bool   ok    = true;

            if (value != null)
            {
                long testValue = Convert.ToInt64(value);
                ok = (testValue >= min) && (testValue <= max);
            }
            if (ok)
            {
                return(true);
            }
            e.Description = String.Format(
                Resources.BetweenRule, e.DisplayPropertyName, min.ToString(), max.ToString());
            return(false);
        }
예제 #11
0
        /// <summary>Rule that check that value matches a given regex pattern.</summary>
        /// <param name="target">Object containing the data to validate</param>
        /// <param name="e">RegExRuleArgs parameter specifying the name of the
        /// property to validate and the regex pattern.</param>
        /// <returns>False if the rule is broken</returns>
        /// <remarks>This implementation uses late binding.</remarks>
        public static bool RegExMatch(object target, RuleArgs e)
        {
            RegExRuleArgs args  = (RegExRuleArgs)e;
            Regex         rx    = args.RegEx;
            string        value = (string)ExtendedReflectionFns.GetPropertyValue(target, args.PropertyName);

            // Contra CSLA, rule does NOT fail if there is no entry;
            // That test is the job of a "PropertyRequired" rule.
            if (value == null || value.Trim() == String.Empty)
            {
                return(true);
            }
            if (!rx.IsMatch(value))
            {
                args.Description =
                    String.Format(args.MessageTemplate, args.DisplayPropertyName);
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #12
0
 /// <summary>Rule ensuring an integer value doesn't go below a specified value.</summary>
 /// <param name="target">Object containing the data to validate.</param>
 /// <param name="e">Arguments parameter specifying the name of the property to validate.</param>
 /// <returns><see langword="false"/> if the rule is broken.</returns>
 /// <remarks>Re-routed Csla version to MinValue(Of T).</remarks>
 public static bool IntegerMinValue(object target, RuleArgs e)
 {
     return(MinValue <int>(target, e));
 }
예제 #13
0
 /// <summary>Creates and initializes the rule.</summary>
 /// <param name="pHandler">The address of the method implementing the rule.</param>
 /// <param name="pArgs">A RuleArgs object.</param>
 public RuleMethod(RuleHandler pHandler, RuleArgs pArgs)
 {
     mHandler = pHandler;
     mArgs    = pArgs;
     MakeRuleName();
 }
예제 #14
0
 /// <summary>Return a rule name from the RuleHandler + RuleArgs.</summary>
 internal string MakeRuleName(RuleHandler pHandler, RuleArgs pArgs)
 {
     return(pHandler.Method.Name + "!" + pArgs.ToString());
 }
예제 #15
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));
        }
예제 #16
0
 /// <summary>Remove a specific rule from the rule list.</summary>
 public void Remove(RuleHandler pHandler, RuleArgs args)
 {
     Remove(pHandler, args.PropertyName);
 }
예제 #17
0
 /// <summary>Creates and initializes the rule.</summary>
 /// <param name="pHandler">The address of the method implementing the rule.</param>
 /// <param name="pPropertyName">The field, property or column to which the rule applies.</param>
 public RuleMethod(RuleHandler pHandler, string pPropertyName)
 {
     mHandler = pHandler;
     mArgs    = new RuleArgs(pPropertyName);
     MakeRuleName();
 }