protected virtual void CopyProperties(Rule rule)
 	{
 		rule.UseErrorMessageProvider = UseErrorMessageProvider;
 		rule.ErrorMessage = ErrorMessage;
 		rule.RuleSet = RuleSet;
 		rule.Severity = Severity;
 	}
        /// <remarks>
        /// null is an invalid value for both <paramref name="rule"/> and <paramref name="errorMessage"/>. 
        /// Due to performance concerns <see cref="ArgumentNullException"/> will no be thrown.
        /// So just don't pass in null or an empty string.
        /// </remarks>
        /// <param name="rule">The <see cref="Rule"/> that this <see cref="ValidationError"/> has been generated from.</param>
        /// <param name="errorMessage">The error message.</param>
		/// <param name="attemptedValue">The invalid member's value</param>
        /// <param name="infoDescriptor">The <see cref="InfoDescriptor"/> that this <see cref="ValidationError"/> has been generated from.</param>
        public ValidationError(Rule rule, string errorMessage, object attemptedValue, InfoDescriptor infoDescriptor)
        {
            //Dont guard these. the performance hit is not worth the minor help it gives developers. 
            Rule = rule;
            ErrorMessage = errorMessage;
			AttemptedValue = attemptedValue;
            InfoDescriptor = infoDescriptor;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
			var numberConversionRule = (NumberConversionRule)rule;
			return numberConversionRule.TypeCode == TypeCode &&
				numberConversionRule.NumberStyles == NumberStyles &&
				numberConversionRule.NumberFormatInfo == NumberFormatInfo;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
            var lengthCollectionRule = (LengthCollectionRule) rule;
            return lengthCollectionRule.ExcludeDuplicatesFromCount == ExcludeDuplicatesFromCount && lengthCollectionRule.Comparer == Comparer;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
            var lengthRule = (LengthRule) rule;
            return lengthRule.Maximum == Maximum && lengthRule.Minimum == Minimum;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
            var customRule = (CustomRule)rule;
            return uniqueHash == customRule.uniqueHash;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
            return (base.IsEquivalent(rule) && ((LengthStringRule) rule).TrimWhiteSpace == TrimWhiteSpace);
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
			var enumConversionRule = (EnumConversionRule)rule;
        	return enumConversionRule.EnumType == EnumType;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
			var dateTimeConversionRule = (DateTimeConversionRule)rule;
			return dateTimeConversionRule.Format == Format &&
				dateTimeConversionRule.DateTimeStyles == DateTimeStyles &&
				dateTimeConversionRule.DateTimeFormatInfo == DateTimeFormatInfo;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
            var regexRule = (RegexRule) rule;
            return regexRule.RegexOptions == RegexOptions && regexRule.ValidationExpression == ValidationExpression;
        }
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
            return true;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Checks if the current <see cref="Rule"/> is equivalent to another <see cref="Rule"/>.
 /// </summary>
 /// <remarks>
 /// Called for each <see cref="Rule"/> in <see cref="RuleCollection"/> when a new <see cref="Rule"/> is added. This method is only called when both the existing <see cref="Rule"/> and the <see cref="Rule"/> being are of the same <see cref="Type"/> and have the same <see cref="RuleSet"/>. So it is safe to directly cast <paramref name="rule"/> to the current type. All properties in <paramref name="rule"/> should be compared to the propeties of the current <see cref="Rule"/>.
 /// </remarks>
 /// <param name="rule">The <see cref="Rule"/> to check for equivalence.</param>
 /// <returns><see langword="true"/> if <paramref name="rule"/> is equivalent to the current <see cref="Rule"/>; otherwise <see langword="false"/>.</returns>
 public abstract bool IsEquivalent(Rule rule);
		/// <inheritdoc />
        public override bool IsEquivalent(Rule rule)
        {
            var comparePropertyRule = (ComparePropertyRule) rule;
            return ((comparePropertyRule.PropertyToCompare == PropertyToCompare) && (CompareOperator == comparePropertyRule.CompareOperator));
        }