| | |
| | | if (propertyAttribute == null) continue; |
| | | |
| | | object? value = propertyInfo.GetValue(data, null); |
| | | // æåæè¿°ï¼åå°éå¤ä»£ç ï¼ |
| | | string propDesc = string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description; |
| | | |
| | | // é空éªè¯ï¼ä¿æä¸åï¼ |
| | | 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, $"{propDesc}ä¸å¯ä¸ºnull", data); |
| | | if (string.IsNullOrEmpty(value.ToString())) return (false, $"{propDesc}ä¸å¯ä¸ºç©ºå符串", 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, $"{propDesc}ä¸å¯ä¸ºnull", data); |
| | | |
| | | // å
³é®ï¼å
å°å¼è½¬æ¢ä¸ºdecimalï¼æ¯æå°æ°ï¼ï¼é¿å
ç´æ¥è½¬intæ¥é |
| | | if (!decimal.TryParse(value.ToString(), out decimal valueDecimal)) |
| | | { |
| | | return (false, $"{propDesc}çå¼ã{value}ã䏿¯ææçæ°å¼æ ¼å¼ï¼éä¸ºæ´æ°æå°æ°ï¼", data); |
| | | } |
| | | |
| | | // å°intç±»åçMinValue转为decimal忝è¾ï¼intå¯éå¼è½¬decimalï¼ |
| | | decimal minValue = propertyAttribute.MinValue; |
| | | 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 (valueDecimal < minValue) |
| | | return (false, $"{propDesc}çå¼ã{value}ãä¸å¯å°äºã{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 (valueDecimal <= minValue) |
| | | return (false, $"{propDesc}çå¼ã{value}ãè¦å¤§äºã{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, $"{propDesc}ä¸å¯ä¸ºnull", data); |
| | | |
| | | // åæ ·å
转decimal |
| | | if (!decimal.TryParse(value.ToString(), out decimal valueDecimal)) |
| | | { |
| | | return (false, $"{propDesc}çå¼ã{value}ã䏿¯ææçæ°å¼æ ¼å¼ï¼éä¸ºæ´æ°æå°æ°ï¼", data); |
| | | } |
| | | |
| | | // int转decimalæ¯è¾ |
| | | decimal maxValue = propertyAttribute.MaxValue; |
| | | 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 (valueDecimal > maxValue) |
| | | return (false, $"{propDesc}çå¼ã{value}ãä¸å¯å¤§äºã{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 (valueDecimal >= maxValue) |
| | | return (false, $"{propDesc}çå¼ã{value}ãè¦å°äºã{maxValue}ã", data); |
| | | } |
| | | } |
| | | |