コード例 #1
0
 /// <summary>
 /// Constructing the validation rule by the property name and error message.
 /// </summary>
 /// <param name="propertyName">Property name</param>
 /// <param name="errorMessage">Error message to be populated on rule falure.</param>
 protected BaseValidationRule(string propertyName, string errorMessage)
 {
     PropertyName = propertyName;
     ErrorMessage = errorMessage;
     //По умолчанию важность критическая
     Severity = RuleSeverities.Error;
 }
コード例 #2
0
        /// <summary>
        /// Constructing the Validation error by the <see cref="BaseValidationRule"/>.
        /// </summary>
        /// <exception cref="ArgumentNullException"> Throws exception in case the passed rule is null</exception>
        public ValidationErrorInfo(BaseValidationRule rule)
        {
            //Contract.Requires<ArgumentNullException>(rule != null);
            if (rule == null)
            {
                throw new ArgumentNullException($"{nameof(rule)} shouln't be null.");
            }

            PropertyName = rule.PropertyName;
            ErrorMessage = rule.ErrorMessage;
            Severity     = rule.Severity;
        }
コード例 #3
0
        /// <summary>
        /// Constructing the attribute based on the rule type, severity type and additional arguments.
        /// </summary>
        /// <param name="ruleType">Rule type. Should be derivered from <see cref="BaseValidationRule"/></param>
        /// <param name="severity">Severity of the rule. More info: <see cref="RuleSeverities"/></param>
        /// <param name="args">Additional arguments list</param>
        /// <exception cref="ArgumentNullException"> Throws argument null exception if the rule type is null.</exception>
        public ValidationRuleAttribute(Type ruleType, RuleSeverities severity, params object[] args)
        {
            //Contract.Requires<ArgumentNullException>(ruleType != null);
            if (ruleType == null)
            {
                throw new ArgumentNullException($"{nameof(ruleType)} shouldn't be null.");
            }

            Rule = Activator.CreateInstance(ruleType, args) as BaseValidationRule;
            if (Rule != null)
            {
                Rule.Severity = severity;
            }
        }
コード例 #4
0
 /// <summary>
 /// Constructing the validation error by the propertyName, error message and severity
 /// </summary>
 /// <remarks> Severity is set default to <see cref="RuleSeverities.Error"/></remarks>
 /// <param name="propertyName">Property name which failed the check</param>
 /// <param name="errorMessage">Message to be populated</param>
 /// <param name="severity">Error Severity level. More info: <see cref="RuleSeverities"/></param>
 public ValidationErrorInfo(string propertyName, string errorMessage, RuleSeverities severity = RuleSeverities.Error)
 {
     PropertyName = propertyName;
     ErrorMessage = errorMessage;
 }