コード例 #1
0
        /// <summary>
        /// Does an equality comparison
        /// </summary>
        /// <returns>Returns a validation result</returns>
        protected override IpValidationResult EqualComparison()
        {
            var retVal = new IpValidationResult();

            if (Value == CompareTo)
            {
                return(retVal);
            }

            retVal.IsValid           = false;
            retVal.ValidationMessage = "The value is not equal to the comparison, causing the validation to fail.";

            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// Does a less than comparison
        /// </summary>
        /// <returns>Returns a validation result</returns>
        protected override IpValidationResult LessThanComparison()
        {
            var retVal = new IpValidationResult();

            if (Value < CompareTo)
            {
                return(retVal);
            }

            retVal.IsValid           = false;
            retVal.ValidationMessage = "The value is not less than the comparison, causing the validation to fail.";

            return(retVal);
        }
コード例 #3
0
        /// <summary>
        /// Comapre with neither start nor end values included
        /// </summary>
        protected override IpValidationResult CompareAllExclusive()
        {
            var retVal = new IpValidationResult();

            if (Value > RangeStart && Value < RangeEnd)
            {
                return(retVal);
            }

            retVal.IsValid           = false;
            retVal.ValidationMessage = "The compared value is not in the range excluding the start and end";

            return(retVal);
        }
コード例 #4
0
        /// <summary>
        /// Compare with just the end inclusive
        /// </summary>
        protected override IpValidationResult CompareEndInclusive()
        {
            var retVal = new IpValidationResult();

            if (Value > RangeStart && Value <= RangeEnd)
            {
                return(retVal);
            }

            retVal.IsValid           = false;
            retVal.ValidationMessage = "The compared value is not in the range inclusive of the end";

            return(retVal);
        }
コード例 #5
0
        /// <summary>
        /// Does a starts with comparison
        /// </summary>
        /// <returns>Rerturns the validation result</returns>
        protected virtual IpValidationResult CompareStartsWith()
        {
            var retVal = new IpValidationResult();

            if (IsCaseSensitive && !Value.StartsWith(CompareTo))
            {
                retVal.IsValid           = false;
                retVal.ValidationMessage = "The case sensitive comparison of the values is not matching";
            }
            else if (!IsCaseSensitive && !Value.StartsWith(CompareTo, StringComparison.OrdinalIgnoreCase))
            {
                retVal.IsValid           = false;
                retVal.ValidationMessage = "The case insensitive comparison of the values is not matching";
            }

            return(retVal);
        }
コード例 #6
0
        /// <summary>
        /// Does a contains comparison
        /// </summary>
        /// <returns>Rerturns the validation result</returns>
        protected virtual IpValidationResult CompareContains()
        {
            var retVal = new IpValidationResult();

            if (IsCaseSensitive && !Value.Contains(CompareTo))
            {
                retVal.IsValid           = false;
                retVal.ValidationMessage = "The case sensitive comparison of the values is not matching";
            }
            else if (!IsCaseSensitive && !Value.ToLower().Contains(CompareTo))
            {
                retVal.IsValid           = false;
                retVal.ValidationMessage = "The case insensitive comparison of the values is not matching";
            }

            return(retVal);
        }
コード例 #7
0
        /// <summary>
        /// Method to perform the validation on an implementation
        /// </summary>
        /// <returns></returns>
        public virtual IpValidationResult Validate()
        {
            var retVal = new IpValidationResult();

            if (CanBeEmpty && Value == null)
            {
                retVal.IsValid           = false;
                retVal.ValidationMessage = "The validated value cannot be null";
            }
            else if (!CanBeEmpty && string.IsNullOrWhiteSpace(Value))
            {
                retVal.IsValid           = false;
                retVal.ValidationMessage = "The validated value cannot be null or empty";
            }

            return(retVal);
        }
コード例 #8
0
        /// <summary>
        /// Method to perform the validation on an implementation
        /// </summary>
        /// <returns></returns>
        public virtual IpValidationResult Validate()
        {
            var retVal = new IpValidationResult();

            foreach (var vtc in ValuesToCompare)
            {
                var validator = new IpStringValueValidator(Value, vtc, IsCaseSensitive);
                var isValid   = validator.Validate().IsValid;

                //If we run into any valid values, return success
                if (isValid)
                {
                    return(retVal);
                }
            }

            retVal.IsValid           = false;
            retVal.ValidationMessage = "None of the values match the possible list, causing validation to fail";

            return(retVal);
        }