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