Synchronization code

This commit is contained in:
sunkaixuan
2024-07-22 17:19:09 +08:00
parent df5e129409
commit 2b695a949d
3 changed files with 22 additions and 5 deletions

View File

@@ -172,6 +172,10 @@ namespace SqlSugar
setValue = Guid.Parse(setValue+"");
}
}
else if (item.UnderType?.IsEnum==true&& setValue!=null)
{
setValue = UtilMethods.ChangeType2(setValue, item.UnderType);
}
item.PropertyInfo.SetValue(parentObj, setValue);
}
}

View File

@@ -828,9 +828,9 @@ namespace SqlSugar
{
var propertyName = kv.Key.Replace("SugarNav_", "");
var propertyInfo = columns.First(i => i.PropertyName == propertyName).PropertyInfo;
if (kv.Value is decimal &&UtilMethods.GetUnderType(propertyInfo.PropertyType).IsIn(typeof(int), typeof(long)))
if (kv.Value is decimal && UtilMethods.GetUnderType(propertyInfo.PropertyType).IsIn(typeof(int), typeof(long)))
{
var changeValue = UtilMethods.ChangeType2(kv.Value, propertyInfo.PropertyType);
propertyInfo.SetValue(addItem, changeValue);
}
@@ -842,7 +842,7 @@ namespace SqlSugar
}
else if (kv.Value == DBNull.Value)
{
propertyInfo.SetValue(addItem,null);
propertyInfo.SetValue(addItem, null);
}
else if (UtilMethods.GetUnderType(propertyInfo.PropertyType) == typeof(Guid) && kv.Value is string)
{
@@ -852,6 +852,10 @@ namespace SqlSugar
{
propertyInfo.SetValue(addItem, Convert.ToInt32(kv.Value));
}
else if (propertyInfo.PropertyType.FullName == "System.Ulid")
{
propertyInfo.SetValue(addItem,UtilMethods.To( kv.Value, propertyInfo.PropertyType));
}
else
{
propertyInfo.SetValue(addItem, kv.Value);

View File

@@ -591,11 +591,20 @@ namespace SqlSugar
{
destinationType = UtilMethods.GetUnderType(destinationType);
var sourceType = value.GetType();
if (destinationType.Name == "DateOnly"&&sourceType==typeof(string))
if (destinationType.Name == "DateOnly" && sourceType == typeof(string))
{
var type = Type.GetType("System.DateOnly", true, true);
var method = type.GetMethods().FirstOrDefault(it => it.GetParameters().Length == 1 && it.Name == "FromDateTime");
return method.Invoke(null, new object[] {Convert.ToDateTime(value)});
return method.Invoke(null, new object[] { Convert.ToDateTime(value) });
}
else if (destinationType.FullName == "System.Ulid")
{
var method = destinationType.GetMyMethod("Parse", 1);
if (method != null)
{
var result = method.Invoke(null, new object[] { value });
return result;
}
}
var destinationConverter = TypeDescriptor.GetConverter(destinationType);
if (destinationConverter != null && destinationConverter.CanConvertFrom(value.GetType()))