/// <summary>
 /// Initializes a new instance with lower and upper bounds, and bound types.
 /// </summary>
 /// <param name="lowerBound">An ISO8601 formatted string representing the lower bound, like "2006-01-20T00:00:00".</param>
 /// <param name="lowerBoundType">The bound type for the lower bound.</param>
 /// <param name="upperBound">An ISO8601 formatted string representing the upper bound, like "2006-01-20T00:00:00".</param>
 /// <param name="upperBoundType">The bound type for the upper bound.</param>
 public DateTimeRangeValidatorAttribute(
     string lowerBound,
     RangeBoundaryType lowerBoundType,
     string upperBound,
     RangeBoundaryType upperBoundType)
     : this(lowerBound, ConvertToISO8601Date(lowerBound, "lowerBound"), lowerBoundType, upperBound, ConvertToISO8601Date(upperBound, "upperBound"), upperBoundType)
 { }
 internal static void ValidateRelativeDatimeValidator(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType, int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType)
 {
     if ((((lowerBound != 0) && (lowerUnit == DateTimeUnit.None)) && (lowerBoundType != RangeBoundaryType.Ignore)) || (((upperBound != 0) && (upperUnit == DateTimeUnit.None)) && (upperBoundType != RangeBoundaryType.Ignore)))
     {
         throw new ArgumentException(Resources.RelativeDateTimeValidatorNotValidDateTimeUnit);
     }
 }
 public DateTimeRangeValidatorAttribute(DateTime lowerBound, RangeBoundaryType lowerBoundType, DateTime upperBound, RangeBoundaryType upperBoundType)
 {
     this.lowerBound = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.upperBoundType = upperBoundType;
 }
 public StringLengthValidatorAttribute(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType)
 {
     this.lowerBound = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.upperBoundType = upperBoundType;
 }
Пример #5
0
 RangeValidatorAttribute(IComparable lowerBound, RangeBoundaryType lowerBoundType, IComparable upperBound, RangeBoundaryType upperBoundType)
 {
     ValidatorArgumentsValidatorHelper.ValidateRangeValidator(lowerBound, lowerBoundType, upperBound, upperBoundType);
     this.lowerBound = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.upperBoundType = upperBoundType;
 }
Пример #6
0
        public NumericRangeValidator(NameValueCollection attributes)
            : base(null, null)
        {
            lowerBoundType = (RangeBoundaryType)Enum.Parse(typeof(RangeBoundaryType), attributes.Get("lowerBoundType"));
            upperBoundType = (RangeBoundaryType)Enum.Parse(typeof(RangeBoundaryType), attributes.Get("upperBoundType"));

            int lower;
            if (int.TryParse(attributes.Get("lowerBound"), out lower))
            {
                lowerBound = lower;
            }
            else
            {
                lowerBound = int.MinValue;
            }

            int upper;
            if (int.TryParse(attributes.Get("upperBound"), out upper))
            {
                upperBound = upper;
            }
            else
            {
                upperBound = int.MaxValue;
            }

            int max;
            if (int.TryParse(attributes.Get("maxLength"), out max))
            {
                maxLength = max;
            }
            else
            {
                maxLength = int.MaxValue;
            }

            if (attributes.Get("mandatoryMessageTemplate") != null)
            {
                this.mandatoryMessageTemplate = attributes.Get("mandatoryMessageTemplate").ToString();
            }

            if (attributes.Get("invalidMessageTemplate") != null)
            {
                this.invalidMessageTemplate = attributes.Get("invalidMessageTemplate").ToString();
            }

            if (attributes.Get("rangeMessageTemplate") != null)
            {
                this.rangeMessageTemplate = attributes.Get("rangeMessageTemplate").ToString();
            }

            if (attributes.Get("maxLengthMessageTemplate") != null)
            {
                this.maxLengthMessageTemplate = attributes.Get("maxLengthMessageTemplate").ToString();
            }
        }
 public RelativeDateTimeValidatorAttribute(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType, int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType)
 {
     ValidatorArgumentsValidatorHelper.ValidateRelativeDatimeValidator(lowerBound, lowerUnit, lowerBoundType, upperBound, upperUnit, upperBoundType);
     this.lowerBound = lowerBound;
     this.lowerUnit = lowerUnit;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.upperUnit = upperUnit;
     this.upperBoundType = upperBoundType;
 }
Пример #8
0
        internal static bool ValidRelativeMonthYear(MonthYear input,
                                                    int lowerBound, MonthYearUnit lowerUnit, RangeBoundaryType lowerBoundType,
                                                    int upperBound, MonthYearUnit upperUnit, RangeBoundaryType upperBoundType)
        {
            DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime lowerDate = DateTime.MinValue;
            DateTime upperDate = DateTime.MaxValue;
            DateTime inputDate = new DateTime(input.Year, input.Month, 1);

            switch (lowerUnit)
            {
                case MonthYearUnit.Month:
                    lowerDate = now.AddMonths(lowerBound * -1);
                    break;
                case MonthYearUnit.Year:
                    lowerDate = now.AddYears(lowerBound * -1);
                    break;
            }
            switch (upperUnit)
            {
                case MonthYearUnit.Month:
                    upperDate = now.AddMonths(upperBound);
                    break;
                case MonthYearUnit.Year:
                    upperDate = now.AddYears(upperBound);
                    break;
            }

            //default the bound check to true - if lowerBoundType is Ignore, no test will be performed.
            bool lowerBoundOk = true;
            if (lowerBoundType == RangeBoundaryType.Inclusive)
            {
                lowerBoundOk = inputDate.CompareTo(lowerDate) >= 0;
            }
            else if (lowerBoundType == RangeBoundaryType.Exclusive)
            {
                lowerBoundOk = inputDate.CompareTo(lowerDate) > 0;
            }

            //default the bound check to true - if upperBoundType is Ignore, no test will be performed.
            bool upperBoundOk = true;
            if (upperBoundType == RangeBoundaryType.Inclusive)
            {
                upperBoundOk = inputDate.CompareTo(upperDate) <= 0;
            }
            else if (upperBoundType == RangeBoundaryType.Exclusive)
            {
                upperBoundOk = inputDate.CompareTo(upperDate) < 0;
            }

            return lowerBoundOk && upperBoundOk;
        }
 public NumericRangeValidatorAttribute(int lowerBound, RangeBoundaryType lowerBoundType,
     int upperBound, RangeBoundaryType upperBoundType, int maxLength,
     string mandatoryMessageTemplate, string invalidMessageTemplate,
     string rangeMessageTemplate, string maxLengthMessageTemplate)
 {
     this.lowerBound = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.upperBoundType = upperBoundType;
     this.maxLength = maxLength;
     this.mandatoryMessageTemplate = mandatoryMessageTemplate;
     this.invalidMessageTemplate = invalidMessageTemplate;
     this.rangeMessageTemplate = rangeMessageTemplate;
     this.maxLengthMessageTemplate = maxLengthMessageTemplate;
 }
        public DateTimeRangeValidatorOperation(
            string keyToValidate,
            string resultKey,
            DateTime lowerBound,
            RangeBoundaryType lowerBoundary,
            DateTime upperBound,
            RangeBoundaryType upperBoundary,

            bool negated) : base(keyToValidate, resultKey) {

            Validator = new DateTimeRangeValidator(
                lowerBound,
                lowerBoundary,
                upperBound,
                upperBoundary,
                negated
            ) { Tag = keyToValidate };
        }
 internal static void ValidateRangeValidator(IComparable lowerBound, RangeBoundaryType lowerBoundaryType, IComparable upperBound, RangeBoundaryType upperBoundaryType)
 {
     if ((lowerBoundaryType != RangeBoundaryType.Ignore) && (lowerBound == null))
     {
         throw new ArgumentNullException("lowerBound");
     }
     if ((upperBoundaryType != RangeBoundaryType.Ignore) && (upperBound == null))
     {
         throw new ArgumentNullException("upperBound");
     }
     if ((lowerBoundaryType == RangeBoundaryType.Ignore) && (upperBoundaryType == RangeBoundaryType.Ignore))
     {
         throw new ArgumentException(Resources.ExceptionCannotIgnoreBothBoundariesInRange, "lowerBound");
     }
     if (((lowerBound != null) && (upperBound != null)) && (lowerBound.GetType() != upperBound.GetType()))
     {
         throw new ArgumentException(Resources.ExceptionTypeOfBoundsMustMatch, "upperBound");
     }
 }
        public StringLengthValidatorOperation(
            string keyToValidate,
            string resultKey,
            int lowerBound,
            RangeBoundaryType lowerBoundaryType,
            int upperBound,
            RangeBoundaryType upperBoundaryType,
            bool negated)
            : base(keyToValidate, resultKey) {

            Validator = new StringLengthValidator(
                lowerBound,
                lowerBoundaryType,
                upperBound,
                upperBoundaryType,
                string.Empty,
                negated
                );
        }
        public RangeValidatorOperation(
            string keyToValidate,
            string resultKey,
            IComparable lowerBound,
            RangeBoundaryType lowerBoundary,
            IComparable upperBound,
            RangeBoundaryType upperBoundary,
            bool negated)
            : base(keyToValidate, resultKey) {

            Validator = new RangeValidator(
                lowerBound,
                lowerBoundary,
                upperBound,
                upperBoundary,
                string.Empty,
                negated
                ) { Tag = keyToValidate };

            }
        public RelativeDateTimeValidatorOperation(
            string keyToValidate,
            string resultKey,
            int lowerBound,
            DateTimeUnit lowerUnit,
            RangeBoundaryType lowerBoundaryType,
            int upperBound,
            DateTimeUnit upperUnit,
            RangeBoundaryType upperBoundaryType,
            bool negated)
            : base(keyToValidate, resultKey) {

            Validator = new RelativeDateTimeValidator(
                lowerBound,
                lowerUnit,
                lowerBoundaryType,
                upperBound,
                upperUnit,
                upperBoundaryType,
                string.Empty,
                negated
            ) { Tag = keyToValidate };
        }
 /// <summary>
 /// Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="Single"/> lower and upper bounds.
 /// </summary>
 /// <param name="lowerBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="lowerBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 /// <param name="upperBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="upperBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 public AssertRangeAttribute(float lowerBound, RangeBoundaryType lowerBoundType, float upperBound, RangeBoundaryType upperBoundType) : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
 private DateTimeRangeValidatorAttribute(
     object lowerBound,
     DateTime effectiveLowerBound,
     RangeBoundaryType lowerBoundType,
     object upperBound,
     DateTime effectiveUpperBound,
     RangeBoundaryType upperBoundType)
 {
     this.lowerBound = lowerBound;
     this.effectiveLowerBound = effectiveLowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.effectiveUpperBound = effectiveUpperBound;
     this.upperBoundType = upperBoundType;
 }
 /// <summary>
 /// Initializes a new instance with lower and upper bounds, and bound types.
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The bound type for the lower bound.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The bound type for the upper bound.</param>
 public DateTimeRangeValidatorAttribute(
     DateTime lowerBound,
     RangeBoundaryType lowerBoundType,
     DateTime upperBound,
     RangeBoundaryType upperBoundType)
     : this(lowerBound, lowerBound, lowerBoundType, upperBound, upperBound, upperBoundType)
 { }
Пример #18
0
 public RelativeDateTimeValidator(int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType, string messageTemplate, bool negated) : this(0, DateTimeUnit.None, RangeBoundaryType.Ignore, upperBound, upperUnit, upperBoundType, messageTemplate, negated)
 {
 }
Пример #19
0
 public RelativeDateTimeValidator(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType, int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType, string messageTemplate) : this(lowerBound, lowerUnit, lowerBoundType, upperBound, upperUnit, upperBoundType, messageTemplate, false)
 {
 }
Пример #20
0
 private RangeValidatorAttribute(IComparable lowerBound, RangeBoundaryType lowerBoundType, IComparable upperBound, RangeBoundaryType upperBoundType)
 {
     ValidatorArgumentsValidatorHelper.ValidateRangeValidator(lowerBound, lowerBoundType, upperBound, upperBoundType);
     this.lowerBound     = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound     = upperBound;
     this.upperBoundType = upperBoundType;
 }
Пример #21
0
 public StringLengthValidator(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType, string messageTemplate, bool negated) : base(messageTemplate, null, negated)
 {
     this.rangeChecker = new RangeChecker <int>(lowerBound, lowerBoundType, upperBound, upperBoundType);
 }
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidator{T}"/> class with fully specified
 /// bound constraints.</para>
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <param name="negated">True if the validator must negate the result of the validation.</param>
 /// <seealso cref="RangeBoundaryType"/>
 protected RangeValidator(T lowerBound, RangeBoundaryType lowerBoundType,
                          T upperBound, RangeBoundaryType upperBoundType, bool negated)
     : this(lowerBound, lowerBoundType, upperBound, upperBoundType, null, negated)
 {
 }
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidator{T}"/> class with fully specified
 /// bound constraints.</para>
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <seealso cref="RangeBoundaryType"/>
 public RangeValidator(T lowerBound, RangeBoundaryType lowerBoundType,
                       T upperBound, RangeBoundaryType upperBoundType)
     : this(lowerBound, lowerBoundType, upperBound, upperBoundType, null)
 {
 }
 internal static void ValidateRelativeDatimeValidator(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType,
                                                      int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType)
 {
     if ((lowerBound != 0 && lowerUnit == DateTimeUnit.None && lowerBoundType != RangeBoundaryType.Ignore) ||
         (upperBound != 0 && upperUnit == DateTimeUnit.None && upperBoundType != RangeBoundaryType.Ignore))
     {
         throw new ArgumentException(Resources.RelativeDateTimeValidatorNotValidDateTimeUnit);
     }
 }
Пример #25
0
 public RangeChecker(T lowerBound, RangeBoundaryType lowerBoundType, T upperBound, RangeBoundaryType upperBoundType)
 {
     if ((upperBound == null) && (upperBoundType != RangeBoundaryType.Ignore))
     {
         throw new ArgumentException(Resources.ExceptionUpperBoundNull);
     }
     if ((lowerBound == null) && (lowerBoundType != RangeBoundaryType.Ignore))
     {
         throw new ArgumentException(Resources.ExceptionLowerBoundNull);
     }
     if (((lowerBoundType != RangeBoundaryType.Ignore) && (upperBoundType != RangeBoundaryType.Ignore)) && (upperBound.CompareTo(lowerBound) < 0))
     {
         throw new ArgumentException(Resources.ExceptionUpperBoundLowerThanLowerBound);
     }
     this.lowerBound     = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound     = upperBound;
     this.upperBoundType = upperBoundType;
 }
        internal static void ValidateRangeValidator(IComparable lowerBound, RangeBoundaryType lowerBoundaryType, IComparable upperBound, RangeBoundaryType upperBoundaryType)
        {
            if (lowerBoundaryType != RangeBoundaryType.Ignore && null == lowerBound)
            {
                throw new ArgumentNullException("lowerBound");
            }
            else if (upperBoundaryType != RangeBoundaryType.Ignore && null == upperBound)
            {
                throw new ArgumentNullException("upperBound");
            }
            else if (lowerBoundaryType == RangeBoundaryType.Ignore && upperBoundaryType == RangeBoundaryType.Ignore)
            {
                throw new ArgumentException(Resources.ExceptionCannotIgnoreBothBoundariesInRange, "lowerBound");
            }

            if (lowerBound != null && upperBound != null && lowerBound.GetType() != upperBound.GetType())
            {
                throw new ArgumentException(Resources.ExceptionTypeOfBoundsMustMatch, "upperBound");
            }
        }
Пример #27
0
 public RangeValidatorAttribute(Type boundType, string lowerBound, RangeBoundaryType lowerBoundType, string upperBound, RangeBoundaryType upperBoundType) : this(ConvertBound(boundType, lowerBound, "lowerBound"), lowerBoundType, ConvertBound(boundType, upperBound, "upperBound"), upperBoundType)
 {
 }
Пример #28
0
 public RangeValidatorAttribute(string lowerBound, RangeBoundaryType lowerBoundType, string upperBound, RangeBoundaryType upperBoundType) : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
Пример #29
0
 private RangeValidatorAttribute(IComparable lowerBound, RangeBoundaryType lowerBoundType,
     IComparable upperBound, RangeBoundaryType upperBoundType)
     : this(null, lowerBound, lowerBound, lowerBoundType, upperBound, upperBound, upperBoundType)
 { }
 public DateTimeRangeValidator(DateTime lowerBound, RangeBoundaryType lowerBoundType, DateTime upperBound, RangeBoundaryType upperBoundType, bool negated) : base(lowerBound, lowerBoundType, upperBound, upperBoundType, negated)
 {
 }
Пример #31
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidatorAttribute"/> class with fully specified
 /// long bound constraints.</para>
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <seealso cref="RangeBoundaryType"/>
 public RangeValidatorAttribute(long lowerBound, RangeBoundaryType lowerBoundType,
         long upperBound, RangeBoundaryType upperBoundType)
     : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 { }
 public DateTimeRangeValidator(DateTime lowerBound, RangeBoundaryType lowerBoundType, DateTime upperBound, RangeBoundaryType upperBoundType, string messageTemplate, bool negated) : base(lowerBound, lowerBoundType, upperBound, upperBoundType, messageTemplate, negated)
 {
 }
Пример #33
0
 public RangeValidator(T lowerBound, RangeBoundaryType lowerBoundType, T upperBound, RangeBoundaryType upperBoundType, string messageTemplate, bool negated)
     : base(messageTemplate, (string)null, negated)
 {
     ValidatorArgumentsValidatorHelper.ValidateRangeValidator((IComparable)(object)lowerBound, lowerBoundType, (IComparable)(object)upperBound, upperBoundType);
     this.rangeChecker = new RangeChecker <T>(lowerBound, lowerBoundType, upperBound, upperBoundType);
 }
Пример #34
0
 public Range(T lowerBound, RangeBoundaryType lowerBoundaryType, T upperBound, RangeBoundaryType upperBoundaryType)
 {
     Invariant.ArgumentEnumIsValidValue((Enum)lowerBoundaryType, "lowerBoundaryType");
     Invariant.ArgumentEnumIsValidValue((Enum)upperBoundaryType, "upperBoundaryType");
     this._lowerBound        = lowerBound;
     this._lowerBoundaryType = lowerBoundaryType;
     this._upperBound        = upperBound;
     this._upperBoundaryType = upperBoundaryType;
     if (!this.IsValid)
     {
         throw new InvalidOperationException();
     }
 }
Пример #35
0
 public RelativeDateTimeValidator(int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType) : this(0, DateTimeUnit.None, RangeBoundaryType.Ignore, upperBound, upperUnit, upperBoundType, false)
 {
 }
 public RelativeDateTimeValidatorAttribute(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType, int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType)
 {
     ValidatorArgumentsValidatorHelper.ValidateRelativeDatimeValidator(lowerBound, lowerUnit, lowerBoundType, upperBound, upperUnit, upperBoundType);
     this.lowerBound     = lowerBound;
     this.lowerUnit      = lowerUnit;
     this.lowerBoundType = lowerBoundType;
     this.upperBound     = upperBound;
     this.upperUnit      = upperUnit;
     this.upperBoundType = upperBoundType;
 }
Пример #37
0
 public RelativeDateTimeValidator(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType, int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType, bool negated) : this(lowerBound, lowerUnit, lowerBoundType, upperBound, upperUnit, upperBoundType, null, negated)
 {
 }
Пример #38
0
 public StringLengthValidatorAttribute(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType)
 {
     this.lowerBound     = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound     = upperBound;
     this.upperBoundType = upperBoundType;
 }
Пример #39
0
        public RelativeDateTimeValidator(int lowerBound, DateTimeUnit lowerUnit, RangeBoundaryType lowerBoundType, int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType, string messageTemplate, bool negated) : base(messageTemplate, null, negated)
        {
            ValidatorArgumentsValidatorHelper.ValidateRelativeDatimeValidator(lowerBound, lowerUnit, lowerBoundType, upperBound, upperUnit, upperBoundType);
            this.lowerBound = lowerBound;
            this.lowerUnit  = lowerUnit;
            this.upperBound = upperBound;
            this.upperUnit  = upperUnit;
            this.generator  = new RelativeDateTimeGenerator();
            DateTime now       = DateTime.Now;
            DateTime dateTime  = this.generator.GenerateBoundDateTime(lowerBound, lowerUnit, now);
            DateTime dateTime2 = this.generator.GenerateBoundDateTime(upperBound, upperUnit, now);

            this.rangeChecker = new RangeChecker <DateTime>(dateTime, lowerBoundType, dateTime2, upperBoundType);
        }
		/// <summary>
		/// <para>Initializes a new instance of the <see cref="RelativeDateTimeValidatorAttribute"/>.</para>
		/// </summary>
		/// <param name="upperBound">The upper bound</param>
		/// <param name="upperUnit">The upper bound unit of time.</param>
		/// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
		public RelativeDateTimeValidatorAttribute(int upperBound, DateTimeUnit upperUnit, RangeBoundaryType upperBoundType)
			: this(0, DateTimeUnit.None, RangeBoundaryType.Ignore, upperBound, upperUnit, upperBoundType)
		{ }
Пример #41
0
 public RangeValidator(T lowerBound, RangeBoundaryType lowerBoundType, T upperBound, RangeBoundaryType upperBoundType, string messageTemplate)
     : this(lowerBound, lowerBoundType, upperBound, upperBoundType, messageTemplate, false)
 {
     this.rangeChecker = new RangeChecker <T>(lowerBound, lowerBoundType, upperBound, upperBoundType);
 }
 /// <summary>
 /// Initializes a new instance of the  <see cref="StringDateTimeRangeValidator"/>
 /// class with fully specified bound constraints.
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 public StringDateTimeRangeValidator(DateTime lowerBound, RangeBoundaryType lowerBoundType, DateTime upperBound, RangeBoundaryType upperBoundType)
     : base(lowerBound, lowerBoundType, upperBound, upperBoundType)
 {
 }
 /// <summary>
 /// Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="String"/> lower and upper bounds.
 /// </summary>
 /// <param name="lowerBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="lowerBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 /// <param name="upperBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="upperBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 public AssertRangeAttribute(string lowerBound, RangeBoundaryType lowerBoundType, string upperBound, RangeBoundaryType upperBoundType) : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
Пример #44
0
 /// <summary>
 /// Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="Decimal"/> lower and upper bounds.
 /// </summary>
 /// <param name="lowerBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="lowerBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 /// <param name="upperBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="upperBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 public AssertRangeAttribute(decimal lowerBound, RangeBoundaryType lowerBoundType, decimal upperBound, RangeBoundaryType upperBoundType)
     : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
Пример #45
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidatorAttribute"/> class with fully specified
 /// bound constraints using string representations of the boundaries.</para>
 /// </summary>
 /// <param name="boundType">The type of the boundaries.</param>
 /// <param name="lowerBound">The lower bound represented with a string, or <see langword="null"/>.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound, or <see langword="null"/>.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <seealso cref="RangeBoundaryType"/>
 public RangeValidatorAttribute(Type boundType, string lowerBound, RangeBoundaryType lowerBoundType,
     string upperBound, RangeBoundaryType upperBoundType)
     : this(boundType, lowerBound, ConvertBound(boundType, lowerBound, "lowerBound"), lowerBoundType,
             upperBound, ConvertBound(boundType, upperBound, "upperBound"), upperBoundType)
 { }
Пример #46
0
 /// <summary>
 /// Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="Single"/> lower and upper bounds.
 /// </summary>
 /// <param name="lowerBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="lowerBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 /// <param name="upperBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="upperBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 public AssertRangeAttribute(float lowerBound, RangeBoundaryType lowerBoundType, float upperBound, RangeBoundaryType upperBoundType)
     : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
Пример #47
0
        private RangeValidatorAttribute(
            Type boundType,
            object lowerBound, IComparable effectiveLowerBound, RangeBoundaryType lowerBoundType,
            object upperBound, IComparable effectiveUpperBound, RangeBoundaryType upperBoundType)
        {
            ValidatorArgumentsValidatorHelper.ValidateRangeValidator(effectiveLowerBound, lowerBoundType, effectiveUpperBound, upperBoundType);

            this.boundType = boundType;
            this.lowerBound = lowerBound;
            this.effectiveLowerBound = effectiveLowerBound;
            this.lowerBoundType = lowerBoundType;
            this.upperBound = upperBound;
            this.effectiveUpperBound = effectiveUpperBound;
            this.upperBoundType = upperBoundType;
        }
Пример #48
0
 internal static bool ValidRelativeMonthYear(MonthYear input, int upperBound, MonthYearUnit upperUnit,
                                             RangeBoundaryType upperBoundType)
 {
     return ValidRelativeMonthYear(input, 0, MonthYearUnit.Year, RangeBoundaryType.Ignore, upperBound, upperUnit, upperBoundType);
 }
Пример #49
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidator"/> class with fully specified
 /// bound constraints and a message template.</para>
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <param name="messageTemplate">The message template to use when logging results.</param>
 /// <param name="negated">True if the validator must negate the result of the validation.</param>
 /// <seealso cref="RangeBoundaryType"/>
 public RangeValidator(IComparable lowerBound, RangeBoundaryType lowerBoundType,
                       IComparable upperBound, RangeBoundaryType upperBoundType,
                       string messageTemplate, bool negated)
     : base(lowerBound, lowerBoundType, upperBound, upperBoundType, messageTemplate, negated)
 {
 }
Пример #50
0
 public RangeValidatorAttribute(DateTime lowerBound, RangeBoundaryType lowerBoundType, DateTime upperBound, RangeBoundaryType upperBoundType) : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
 /// <summary>
 /// Initializes a new instance of the  <see cref="StringDateTimeRangeValidator"/>
 /// class with fully specified bound constraints and a message template.
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <param name="messageTemplate">The message template to use when logging results.</param>
 /// <param name="negated">True if the validator must negate the result of the validation.</param>
 public StringDateTimeRangeValidator(DateTime lowerBound, RangeBoundaryType lowerBoundType, DateTime upperBound, RangeBoundaryType upperBoundType, string messageTemplate, bool negated)
     : base(lowerBound, lowerBoundType, upperBound, upperBoundType, messageTemplate, negated)
 {
 }
Пример #52
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidator"/> class with fully specified
 /// bound constraints.</para>
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <seealso cref="RangeBoundaryType"/>
 public RangeValidator(IComparable lowerBound, RangeBoundaryType lowerBoundType,
                       IComparable upperBound, RangeBoundaryType upperBoundType)
     : this(lowerBound, lowerBoundType, upperBound, upperBoundType, null)
 {
 }
Пример #53
0
 /// <summary>
 /// Initialize a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="Double"/> lower and upper bounds.
 /// </summary>
 /// <param name="lowerBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="lowerBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 /// <param name="upperBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="upperBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 public DenyRangeAttribute(double lowerBound, RangeBoundaryType lowerBoundType, double upperBound, RangeBoundaryType upperBoundType) : base((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
Пример #54
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidator"/> class with fully specified
 /// bound constraints and a message template.</para>
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <param name="messageTemplate">The message template to use when logging results.</param>
 /// <seealso cref="RangeBoundaryType"/>
 public RangeValidator(IComparable lowerBound, RangeBoundaryType lowerBoundType,
                       IComparable upperBound, RangeBoundaryType upperBoundType,
                       string messageTemplate)
     : this(lowerBound, lowerBoundType, upperBound, upperBoundType, messageTemplate, false)
 {
 }
Пример #55
0
        /// <summary>
        /// Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="IComparable"/> lower and upper bounds.
        /// </summary>
        /// <param name="lowerBound">
        /// The lower bound of the range.
        /// </param>
        /// <param name="lowerBoundType">
        /// One of the <see cref="RangeBoundaryType"/> values.
        /// </param>
        /// <param name="upperBound">
        /// The lower bound of the range.
        /// </param>
        /// <param name="upperBoundType">
        /// One of the <see cref="RangeBoundaryType"/> values.
        /// </param>
        protected AssertRangeAttribute(IComparable lowerBound, RangeBoundaryType lowerBoundType, IComparable upperBound, RangeBoundaryType upperBoundType)
        {
            if (null == lowerBound) throw new ArgumentNullException("lowerBound");
            if (null == upperBound) throw new ArgumentNullException("upperBound");

            if (lowerBound.CompareTo(upperBound) > 0)
            {
                throw new ArgumentOutOfRangeException("lowerBound", string.Format(CultureInfo.CurrentUICulture, Resources.ExceptionLowerBoundOutOfRange, lowerBound.ToString(), upperBound.ToString()));
            }
            this.lowerBound = lowerBound;
            this.lowerBoundType = lowerBoundType;
            this.upperBound = upperBound;
            this.upperBoundType = upperBoundType;
        }
Пример #56
0
 public StringLengthValidator(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType, bool negated) : this(lowerBound, lowerBoundType, upperBound, upperBoundType, null, negated)
 {
 }
Пример #57
0
 /// <summary>
 /// Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="String"/> lower and upper bounds.
 /// </summary>
 /// <param name="lowerBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="lowerBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 /// <param name="upperBound">
 /// The lower bound of the range.
 /// </param>
 /// <param name="upperBoundType">
 /// One of the <see cref="RangeBoundaryType"/> values.
 /// </param>
 public AssertRangeAttribute(string lowerBound, RangeBoundaryType lowerBoundType, string upperBound, RangeBoundaryType upperBoundType)
     : this((IComparable)lowerBound, lowerBoundType, (IComparable)upperBound, upperBoundType)
 {
 }
Пример #58
0
 public StringLengthValidator(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType, string messageTemplate) : this(lowerBound, lowerBoundType, upperBound, upperBoundType, messageTemplate, false)
 {
     this.rangeChecker = new RangeChecker <int>(lowerBound, lowerBoundType, upperBound, upperBoundType);
 }
Пример #59
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="RangeValidator"/> class with fully specified
 /// bound constraints.</para>
 /// </summary>
 /// <param name="lowerBound">The lower bound.</param>
 /// <param name="lowerBoundType">The indication of how to perform the lower bound check.</param>
 /// <param name="upperBound">The upper bound.</param>
 /// <param name="upperBoundType">The indication of how to perform the upper bound check.</param>
 /// <param name="negated">True if the validator must negate the result of the validation.</param>
 /// <seealso cref="RangeBoundaryType"/>
 public RangeValidator(IComparable lowerBound, RangeBoundaryType lowerBoundType,
                       IComparable upperBound, RangeBoundaryType upperBoundType, bool negated)
     : this(lowerBound, lowerBoundType, upperBound, upperBoundType, null, negated)
 {
 }
Пример #60
0
 /// <summary>
 /// <para>Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="IComparable"/> lower and upper bounds.</para>
 /// </summary>
 /// <param name="lowerBound">
 /// <para>The lower bound of the range.</para>
 /// </param>
 /// <param name="lowerBoundType">
 /// <para>One of the <see cref="RangeBoundaryType"/> values.</para>
 /// </param>
 /// <param name="upperBound">
 /// <para>The lower bound of the range.</para>
 /// </param>
 /// <param name="upperBoundType">
 /// <para>One of the <see cref="RangeBoundaryType"/> values.</para>
 /// </param>
 protected AssertRangeAttribute(IComparable lowerBound, RangeBoundaryType lowerBoundType, IComparable upperBound, RangeBoundaryType upperBoundType)
 {
     if (lowerBound.CompareTo(upperBound) > 0)
     {
         throw new ArgumentOutOfRangeException("lowerBound", SR.ExceptionLowerBoundOutOfRange(lowerBound.ToString(), upperBound.ToString()));
     }
     this.lowerBound = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.upperBoundType = upperBoundType;
 }