feat: 增加枚举类型入库时 ToString

This commit is contained in:
Argo-Tianyi 2021-12-21 23:40:50 +08:00
parent fa6c0e302f
commit 4a3582748b
1 changed files with 7 additions and 8 deletions

View File

@ -64,13 +64,12 @@ namespace BootstrapAdmin.DataAccess.PetaPoco
return ci;
}
public override Func<object?, object?> GetFromDbConverter(PropertyInfo targetProperty, Type sourceType)
{
if (targetProperty.PropertyType.IsEnum && sourceType == typeof(string))
{
return new StringToEnumConverter(targetProperty.PropertyType).ConvertFromDb;
}
return base.GetFromDbConverter(targetProperty, sourceType);
}
public override Func<object?, object?> GetFromDbConverter(PropertyInfo targetProperty, Type sourceType) => targetProperty.PropertyType.IsEnum && sourceType == typeof(string)
? new StringToEnumConverter(targetProperty.PropertyType).ConvertFromDb
: base.GetFromDbConverter(targetProperty, sourceType);
public override Func<object?, object?> GetToDbConverter(PropertyInfo targetProperty) => targetProperty.PropertyType.IsEnum
? new StringToEnumConverter(targetProperty.PropertyType).ConvertToDb
: base.GetToDbConverter(targetProperty);
}
}