| | |
| | | if (propertyAttribute == null) continue; |
| | | |
| | | object? value = propertyInfo.GetValue(data, null); |
| | | if (value is IList) |
| | | { |
| | | IList list = (IList)value; |
| | | Type? t = list.GetType().GetGenericArguments().FirstOrDefault(); |
| | | if (t != null && t.IsClass) |
| | | { |
| | | foreach (var item in list) |
| | | { |
| | | (bool, string, object?) result = ValidateModelData(item, t); |
| | | if (!result.Item1) return result; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (propertyAttribute.NotNullAndEmpty) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (string.IsNullOrEmpty(value.ToString())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºç©ºå符串", data); |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})ä¸å¯ä¸ºnull", data); |
| | | if (string.IsNullOrEmpty(value.ToString())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})ä¸å¯ä¸ºç©ºå符串", data); |
| | | } |
| | | |
| | | if (propertyAttribute.MinValue > int.MinValue) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})ä¸å¯ä¸ºnull", data); |
| | | if (propertyAttribute.IsContainMinValue) |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) < propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãä¸å¯å°äºã{propertyAttribute.MinValue}ã", data); |
| | | if (Convert.ToInt32(value.ToString()) < propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})çå¼ã{value}ãä¸å¯å°äºã{propertyAttribute.MinValue}ã", data); |
| | | } |
| | | else |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) <= propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãè¦å¤§äºã{propertyAttribute.MinValue}ã", data); |
| | | if (Convert.ToInt32(value.ToString()) <= propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})çå¼ã{value}ãè¦å¤§äºã{propertyAttribute.MinValue}ã", data); |
| | | } |
| | | } |
| | | |
| | | if (propertyAttribute.MaxValue < int.MaxValue) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})ä¸å¯ä¸ºnull", data); |
| | | if (propertyAttribute.IsContainMaxValue) |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) >= propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãä¸å¯å¤§äºã{propertyAttribute.MaxValue}ã", data); |
| | | if (Convert.ToInt32(value.ToString()) >= propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})çå¼ã{value}ãä¸å¯å¤§äºã{propertyAttribute.MaxValue}ã", data); |
| | | } |
| | | else |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) > propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãè¦å°äºã{propertyAttribute.MaxValue}ã", data); |
| | | if (Convert.ToInt32(value.ToString()) > propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})çå¼ã{value}ãè¦å°äºã{propertyAttribute.MaxValue}ã", data); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (propertyAttribute.Check != null && propertyAttribute.Check.Length > 0) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (propertyAttribute.Check.FirstOrDefault(x => x.ToString() == value.ToString()) == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}使ç¨äºCheck约æï¼ä¼ å
¥çå¼ä¸å¨{propertyAttribute.Check.Serialize()}ä¸", data); |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})ä¸å¯ä¸ºnull", data); |
| | | if (propertyAttribute.Check.FirstOrDefault(x => x.ToString() == value.ToString()) == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})使ç¨äºCheck约æï¼ä¼ å
¥çå¼ä¸å¨{propertyAttribute.Check.Serialize()}ä¸", data); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(propertyAttribute.StartWith) && !string.IsNullOrWhiteSpace(propertyAttribute.EndWith)) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})ä¸å¯ä¸ºnull", data); |
| | | else |
| | | { |
| | | if (value.ToString().StartsWith(propertyAttribute.StartWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}å¿
须以{propertyAttribute.StartWith}å¼å¤´", data); |
| | | if (value.ToString().StartsWith(propertyAttribute.StartWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})å¿
须以{propertyAttribute.StartWith}å¼å¤´", data); |
| | | } |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(propertyAttribute.EndWith) && !string.IsNullOrWhiteSpace(propertyAttribute.EndWith)) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})ä¸å¯ä¸ºnull", data); |
| | | else |
| | | { |
| | | if (value.ToString().EndsWith(propertyAttribute.EndWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}å¿
须以{propertyAttribute.EndWith}ç»å°¾", data); |
| | | if (value.ToString().EndsWith(propertyAttribute.EndWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})å¿
须以{propertyAttribute.EndWith}ç»å°¾", data); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | if (value.ToString().Length < propertyAttribute.MinLength) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼å°äºæå°é¿åº¦ã{propertyAttribute.MinLength}ãï¼æ°æ®:{value}", data); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | catch (Exception ex) |