Hishop.Components.Validation/Validators/RangeValidatorAttribute.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace Hishop.Components.Validation.Validators
{
    using Hishop.Components.Validation;
    using Hishop.Components.Validation.Properties;
    using System;
    using System.ComponentModel;
    using System.Globalization;

    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
    public sealed class RangeValidatorAttribute : ValueValidatorAttribute
    {
        private IComparable lowerBound;
        private RangeBoundaryType lowerBoundType;
        private IComparable upperBound;
        private RangeBoundaryType upperBoundType;

        public RangeValidatorAttribute(DateTime lowerBound, RangeBoundaryType lowerBoundType, DateTime upperBound, RangeBoundaryType upperBoundType) : this((IComparable) lowerBound, lowerBoundType, (IComparable) upperBound, upperBoundType)
        {
        }

        public RangeValidatorAttribute(double lowerBound, RangeBoundaryType lowerBoundType, double upperBound, RangeBoundaryType upperBoundType) : this((IComparable) lowerBound, lowerBoundType, (IComparable) upperBound, upperBoundType)
        {
        }

        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;
        }

        public RangeValidatorAttribute(int lowerBound, RangeBoundaryType lowerBoundType, int upperBound, RangeBoundaryType upperBoundType) : this((IComparable) lowerBound, lowerBoundType, (IComparable) upperBound, upperBoundType)
        {
        }

        public RangeValidatorAttribute(long lowerBound, RangeBoundaryType lowerBoundType, long upperBound, RangeBoundaryType upperBoundType) : this((IComparable) lowerBound, lowerBoundType, (IComparable) upperBound, upperBoundType)
        {
        }

        public RangeValidatorAttribute(float lowerBound, RangeBoundaryType lowerBoundType, float upperBound, RangeBoundaryType upperBoundType) : this((IComparable) lowerBound, lowerBoundType, (IComparable) upperBound, upperBoundType)
        {
        }

        public RangeValidatorAttribute(string lowerBound, RangeBoundaryType lowerBoundType, string upperBound, RangeBoundaryType upperBoundType) : this((IComparable) lowerBound, lowerBoundType, (IComparable) upperBound, upperBoundType)
        {
        }

        public RangeValidatorAttribute(Type boundType, string lowerBound, RangeBoundaryType lowerBoundType, string upperBound, RangeBoundaryType upperBoundType) : this(ConvertBound(boundType, lowerBound, "lowerBound"), lowerBoundType, ConvertBound(boundType, upperBound, "upperBound"), upperBoundType)
        {
        }

        private static IComparable ConvertBound(Type boundType, string bound, string boundParameter)
        {
            IComparable comparable;
            if (boundType == null)
            {
                throw new ArgumentNullException("boundType");
            }
后面还有 69 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。