public override void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            var parentvalue = propInfo.GetValue(obj);

            if (parentvalue == null)
            {
                return;
            }

            object childvalue = null;

            if (string.IsNullOrEmpty(ChildPropertyName))
            {
                childvalue = ((IKeyHandler)obj).GetKey();
            }
            else
            {
                var propDescrs = TypeDescriptor.GetProperties(obj);
                var childprop  = propDescrs.Find(ChildPropertyName, true);
                if (childprop != null)
                {
                    childvalue = childprop.GetValue(obj);
                }
            }
            if (childvalue == null)
            {
                return;
            }

            if (Equals(childvalue, parentvalue))
            {
                errorsList.Add(new ValidateError(Description, Level));
            }
        }
Exemplo n.º 2
0
        public void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            var strategy = _strategies[StrategyName];

            if (strategy == null)
            {
                throw new DeveloperException(string.Format("Strategy '{0}' is not registered for validate",
                                                           string.IsNullOrEmpty(StrategyName) ? "NULL" : StrategyName));
            }

            strategy(obj, propInfo, errorsList);
        }
Exemplo n.º 3
0
        public override void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            var value = propInfo.GetValue(obj);

            if (value == null)
            {
                return;
            }

            if (Values.Any(i => i.Equals(value)))
            {
                errorsList.Add(new ValidateError(string.Format(Description, value), Level));
            }
        }
Exemplo n.º 4
0
        public override void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            var value = propInfo.GetValue(obj);

            if (value == null)
            {
                return;
            }

            if (value.ToString().Length > MaxLength)
            {
                errorsList.Add(new ValidateError(Description, Level));
            }
        }
Exemplo n.º 5
0
        public override void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            var value = propInfo.GetValue(obj);

            if (value == null)
            {
                errorsList.Add(new ValidateError(Description, Level));
                return;
            }

            if ((value is DateTime && value.Equals(DateTime.MinValue)) ||
                (value is Guid && value.Equals(Guid.Empty)) ||
                (value is string && string.IsNullOrEmpty((string)value)) ||
                (value is IList && ((IList)value).Count == 0))
            {
                errorsList.Add(new ValidateError(Description, Level));
            }
        }
Exemplo n.º 6
0
        public override void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            if (propInfo.PropertyType != typeof(DateTime) && propInfo.PropertyType != typeof(DateTime?))
            {
                throw new DeveloperException(string.Format(DeveloperExceptionResources.IncorrectUseOfAttribute, "DateFutureAttribute", "DateTime"));
            }

            var value = propInfo.GetValue(obj);

            if (value == null)
            {
                return;
            }

            if (((DateTime)value) > DateTime.Now)
            {
                errorsList.Add(new ValidateError(Description, Level));
            }
        }
Exemplo n.º 7
0
        public void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            // получаем стратегию
            var strategy = _strategies[_valid.Value.ObjectValidName];

            if (strategy == null)
            {
                throw new DeveloperException("Strategy '{0}' is not registered for validate", _valid.Value.ObjectValidName ?? "NULL");
            }

            // запускаем стратегию
            var context = new ValidateStrategyContext(obj, propInfo, _valid.Value.ObjectValidParameters, _valid.Value.ObjectValidValue)
            {
                ErrorMessage = _valid.Value.ObjectValidMessage
            };

            if (strategy(context))
            {
                errorsList.Add(new ValidateError(context.ErrorMessage, _valid.Value.ObjectValidLevel));
            }
        }
Exemplo n.º 8
0
        public override void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList)
        {
            if (string.IsNullOrEmpty(MethodName))
            {
                throw new DeveloperException("Can't use ValidateMethodAttribute without method name");
            }

            var vaidatable = obj as IValidatable;

            if (vaidatable == null || vaidatable.Validator == null)
            {
                throw new DeveloperException(string.Format("Object '{0}' is not validatable or Validator not exist", obj));
            }

            var method = GetMethod(vaidatable.Validator.GetType());

            if (method == null)
            {
                throw new DeveloperException(string.Format("Method '{0}' not found", MethodName));
            }

            var methodParams        = method.GetParameters();
            var recomendationsExist = Description != DefaultDescription || Level != DefaultValidatetionLevel;

            if (recomendationsExist || methodParams.Length == 3)
            {
                method.Invoke(vaidatable.Validator, new object[] { errorsList, Description, Level });
            }
            else if (methodParams.Length == 1)
            {
                method.Invoke(vaidatable.Validator, new object[] { errorsList });
            }
            else
            {
                throw new DeveloperException("Params count error in method " + MethodName);
            }
        }
Exemplo n.º 9
0
 public abstract void Validate(object obj, PropertyDescriptor propInfo, ValidateErrorsList errorsList);