Optimized code

This commit is contained in:
sunkaixuan
2023-12-27 12:21:41 +08:00
parent 81f8172a56
commit 515684c10d

View File

@@ -504,6 +504,7 @@ namespace SqlSugar
addValue =UtilMethods.GetFormatValue(addValue,valueFomatInfo); addValue =UtilMethods.GetFormatValue(addValue,valueFomatInfo);
} }
var type = UtilMethods.GetUnderType(item.PropertyType);
if (addValue == DBNull.Value || addValue == null) if (addValue == DBNull.Value || addValue == null)
{ {
if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType)) if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
@@ -527,18 +528,22 @@ namespace SqlSugar
addValue = null; addValue = null;
} }
} }
else if (UtilMethods.GetUnderType(item.PropertyType) == UtilConstants.IntType) else if (type == UtilConstants.IntType)
{ {
addValue = Convert.ToInt32(addValue); addValue = Convert.ToInt32(addValue);
} }
else if (UtilMethods.GetUnderType(item.PropertyType) == UtilConstants.LongType) else if (type == UtilConstants.LongType)
{ {
addValue = Convert.ToInt64(addValue); addValue = Convert.ToInt64(addValue);
} }
else if (UtilMethods.GetUnderType(item.PropertyType).IsEnum() && addValue is decimal) else if (type.IsEnum() && addValue is decimal)
{ {
addValue = Convert.ToInt64(addValue); addValue = Convert.ToInt64(addValue);
} }
else if (type.FullName == "System.DateOnly")
{
addValue = Convert.ToDateTime(addValue).ToString("yyyy-MM-dd");
}
result.Add(name, addValue); result.Add(name, addValue);
} }
} }