Exemplo n.º 1
0
 protected abstract void Validate(TValue value, ValidationResult result);
Exemplo n.º 2
0
 public sealed override void RunMemberValidation(object parentInstance, MemberInfo member, object memberValue, UnityEngine.Object root, ref ValidationResult result)
 {
     throw new NotSupportedException("Value validators cannot validate members");
 }
Exemplo n.º 3
0
        public sealed override void RunValueValidation(object value, UnityEngine.Object root, ref ValidationResult result)
        {
            if (result == null)
            {
                result = new ValidationResult();
            }

            result.Setup = new ValidationSetup()
            {
                Kind      = ValidationKind.Value,
                Validator = this,
                Value     = value,
                Root      = root,
            };

            result.ResultValue = null;
            result.ResultType  = ValidationResultType.Valid;
            result.Message     = "";

            try
            {
                this.Validate((TValue)value, result);
            }
            catch (Exception ex)
            {
                while (ex is TargetInvocationException)
                {
                    ex = ex.InnerException;
                }

                result.ResultType = ValidationResultType.Error;
                result.Message    = "An exception was thrown during validation: " + ex.ToString();
            }
        }
Exemplo n.º 4
0
        protected override void Validate(object parentInstance, T memberValue, MemberInfo member, ValidationResult result)
        {
            if (this.minValueGetter.Failed || this.maxValueGetter.Failed || this.rangeGetter.Failed)
            {
                result.Message    = ValueResolverUtility.CombineErrorMessagesWhereFailed(this.minValueGetter, this.maxValueGetter, this.rangeGetter);
                result.ResultType = ValidationResultType.Error;
                return;
            }

            this.valueExpressionArgument = memberValue;
            this.minValueGetter.DefaultParentInstance = parentInstance;
            this.maxValueGetter.DefaultParentInstance = parentInstance;
            var range = this.rangeGetter.GetValue(parentInstance);

            if (!GenericNumberUtility.NumberIsInRange(memberValue, range.x, range.y))
            {
                result.Message    = "Number is not in range.";
                result.ResultType = ValidationResultType.Error;
            }
        }