Beispiel #1
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            if (value is string stringVal)
            {
                if (stringVal.Length > _maxLength)
                {
                    UpdateVal(val, value, stringVal.Length);
                }
            }

            else if (value is ICollection collection)
            {
                var len = collection.Count;
                if (len > _maxLength)
                {
                    UpdateVal(val, value, len);
                }
            }

            return(val);
        }
Beispiel #2
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };
            var flag = true;

            if (value is ICollection collection)
            {
                if (collection.Cast <object>().Any(one => !_func.Invoke(one)))
                {
                    flag = false;
                }

                if (!flag)
                {
                    UpdateVal(val, value);
                }
            }
            else
            {
                UpdateVal(val, value, "The type is not a collection or an array, and an exception occurs when using AllToken.");
            }

            return(val);
        }
Beispiel #3
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            if (value is string stringVal)
            {
                if (stringVal.Length < _minLength)
                {
                    UpdateVal(val, value, stringVal.Length);
                }
            }

            else if (Member.MemberType == typeof(string) && _minLength > 0)
            {
                UpdateVal(val, value, 0);
            }

            else if (value is ICollection collection)
            {
                var len = collection.Count;
                if (len < _minLength)
                {
                    UpdateVal(val, value, len);
                }
            }

            return(val);
        }
Beispiel #4
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            if (_types.Any())
            {
                var flag        = false;
                var typeOfValue = value?.GetType();

                foreach (var type in _types)
                {
                    if (Member.MemberType == type || (typeOfValue != null && typeOfValue == type))
                    {
                        flag = true;
                        break;
                    }

                    if (Member.MemberType.IsDeriveClassFrom(type))
                    {
                        flag = true;
                        break;
                    }
                }

                if (!flag)
                {
                    UpdateVal(val, value);
                }
            }

            return(val);
        }
        private void UpdateVal(CorrectVerifyVal val, object obj, string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                message = "The value does not satisfy the given Func condition.";
            }

            val.IsSuccess     = false;
            val.VerifiedValue = obj;
            val.ErrorMessage  = MergeMessage(message);
        }
Beispiel #6
0
        public override CorrectVerifyVal ValidValue(TVal value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            if (_objects.Contains(value))
            {
                UpdateVal(val, value);
            }

            return(val);
        }
Beispiel #7
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {NameOfExecutedRule = NAME};

            var success = !ValidCore(value);

            if (!success)
            {
                UpdateVal(val, value);
            }

            return val;
        }
Beispiel #8
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            if (!ValidCore(value))
            {
                UpdateVal(val, value);
            }

            return(val);
        }
        private void UpdateVal(CorrectVerifyVal val, object obj, string expression = null)
        {
            var message = "The regular expression match failed.";

            if (!string.IsNullOrWhiteSpace(expression))
            {
                message += $" The current expression is: {expression}.";
            }

            val.IsSuccess     = false;
            val.VerifiedValue = obj;
            val.ErrorMessage  = MergeMessage(message);
        }
Beispiel #10
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            var regex = _regexFunc(value);

            if (regex == null || value == null || !regex.IsMatch((string)value))
            {
                UpdateVal(val, value, regex?.ToString());
            }

            return(val);
        }
Beispiel #11
0
        public override CorrectVerifyVal ValidValue(TVal value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            var result = _func.Invoke(value);

            if (result != null && !result.VerifyResult)
            {
                UpdateVal(val, value, result.ErrorMessage);
            }

            return(val);
        }
Beispiel #12
0
        public override CorrectVerifyVal ValidValue(TVal value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            var success = ValidCore(value, out var message);

            if (!success)
            {
                UpdateVal(val, value, message);
            }

            return(val);
        }
Beispiel #13
0
        public override CorrectVerifyVal ValidValue(object value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            if (value is decimal decimalValue)
            {
                var scale                 = GetScale(decimalValue);
                var precision             = GetPrecision(decimalValue);
                var actualIntegerDigits   = precision - scale;
                var expectedIntegerDigits = Precision - Scale;

                if (scale > Scale || actualIntegerDigits > expectedIntegerDigits)
                {
                    UpdateVal(val, value, scale, actualIntegerDigits);
                }
            }

            return(val);
        }
Beispiel #14
0
        public override CorrectVerifyVal ValidValue(TVal value)
        {
            var val = new CorrectVerifyVal {
                NameOfExecutedRule = NAME
            };

            if (value is null)
            {
                UpdateVal(val, default);
            }

            if (value is IComparable <TVal> comparable)
            {
                if (_options == RangeOptions.OpenInterval)
                {
                    // Open Interval
                    if (comparable.CompareTo(_from) <= 0 || comparable.CompareTo(_to) >= 0)
                    {
                        UpdateVal(val, value);
                    }
                }
                else
                {
                    // Close Interval
                    if (comparable.CompareTo(_from) < 0 || comparable.CompareTo(_to) > 0)
                    {
                        UpdateVal(val, value);
                    }
                }
            }

            else
            {
                UpdateVal(val, value, "The given value cannot be compared.");
            }

            return(val);
        }
Beispiel #15
0
 private void UpdateVal(CorrectVerifyVal val, object obj, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? $"The given value must be less than or equal to {_valueToCompare}.");
 }
Beispiel #16
0
 private void UpdateVal(CorrectVerifyVal val, object obj, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? $"'{VerifiableMember.MemberName}' has a range of values which does not include '{obj}'.");
 }
Beispiel #17
0
 private void UpdateVal(CorrectVerifyVal val, object obj, int currentLength)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage($"The array length should be greater than {_minLength} and less than {_maxLength}, and the current length is {currentLength}.");
 }
Beispiel #18
0
 private void UpdateVal(CorrectVerifyVal val, TVal obj)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage($"The two values given must be equal. The current value is: {obj} and the value being compared is {_valueToCompare}.");
 }
Beispiel #19
0
 private void UpdateVal(CorrectVerifyVal val, TVal obj)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(GetDefaultMessageSinceToken(obj));
 }
Beispiel #20
0
 /// <inheritdoc />
 protected override void UpdateVal(CorrectVerifyVal val, object obj, object valueToCompare, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? $"The given value must be less than {valueToCompare}.");
 }
 private void UpdateVal(CorrectVerifyVal val, object obj, int actualScale, int actualIntegerDigits)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage($"The given value must not be more than {Precision} digits in total, with allowance for {Scale} decimals. {actualIntegerDigits} digits and {actualScale} decimals were found.");
 }
Beispiel #22
0
 private void UpdateVal(CorrectVerifyVal val, TVal obj, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? $"The given value is not in the valid range. The current value is: {obj}, and the valid range is from {_from} to {_to}.");
 }
Beispiel #23
0
 protected virtual void UpdateVal(CorrectVerifyVal val, object obj, object valueToCompare, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? $"The given value does not meet the requirements.");
 }
Beispiel #24
0
 private void UpdateVal(CorrectVerifyVal val, TVal obj, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? $"The values must not be equal. The current value type is: {Member.MemberType.GetDevelopName()}.");
 }
Beispiel #25
0
 private void UpdateVal(CorrectVerifyVal val, TVal obj, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? "There are no members that meet the conditions in the array or collection.");
 }
Beispiel #26
0
 private void UpdateVal(CorrectVerifyVal val, object obj)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage("The given value is not a member of the specified enumeration type.");
 }
Beispiel #27
0
 private void UpdateVal(CorrectVerifyVal val, object obj)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage($"The given type is not a derived class of {_type.GetDevelopName()} or its implementation. The current type is {Member.MemberType.GetDevelopName()}.");
 }
Beispiel #28
0
 private void UpdateVal(CorrectVerifyVal val, TVal obj, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? "There is at least one unsatisfied member in the array or collection.");
 }
Beispiel #29
0
 private void UpdateVal(CorrectVerifyVal val, object obj, string message = null)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage(message ?? "The value is not contained in the given value array or collection.");
 }
Beispiel #30
0
 private void UpdateVal(CorrectVerifyVal val, object obj)
 {
     val.IsSuccess     = false;
     val.VerifiedValue = obj;
     val.ErrorMessage  = MergeMessage("The value is must be null.");
 }