mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-11-29 18:38:08 +08:00
Merge pull request #624 from jiaguangli/master
add all type nullable support
This commit is contained in:
commit
273fe9756f
@ -75,7 +75,11 @@
|
||||
|
||||
private static object TypeMappingImpl<T>(T v, ExcelColumnInfo pInfo, ref object newValue, object itemValue, Configuration _config) where T : class, new()
|
||||
{
|
||||
if (pInfo.ExcludeNullableType == typeof(Guid))
|
||||
if (pInfo.Nullable && string.IsNullOrWhiteSpace(itemValue?.ToString()))
|
||||
{
|
||||
newValue = null;
|
||||
}
|
||||
else if (pInfo.ExcludeNullableType == typeof(Guid))
|
||||
{
|
||||
newValue = Guid.Parse(itemValue.ToString());
|
||||
}
|
||||
@ -122,8 +126,6 @@
|
||||
newValue = _v2;
|
||||
else if (double.TryParse(vs, NumberStyles.None, CultureInfo.InvariantCulture, out var _d))
|
||||
newValue = DateTimeHelper.FromOADate(_d);
|
||||
else if (pInfo.Nullable && string.IsNullOrWhiteSpace(vs))
|
||||
newValue = null;
|
||||
else
|
||||
throw new InvalidCastException($"{vs} can't cast to datetime");
|
||||
}
|
||||
@ -151,15 +153,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pInfo.Nullable && string.IsNullOrWhiteSpace(itemValue?.ToString()))
|
||||
{
|
||||
newValue = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use pInfo.ExcludeNullableType to resolve : https://github.com/shps951023/MiniExcel/issues/138
|
||||
newValue = Convert.ChangeType(itemValue, pInfo.ExcludeNullableType, _config.Culture);
|
||||
}
|
||||
// Use pInfo.ExcludeNullableType to resolve : https://github.com/shps951023/MiniExcel/issues/138
|
||||
newValue = Convert.ChangeType(itemValue, pInfo.ExcludeNullableType, _config.Culture);
|
||||
}
|
||||
|
||||
pInfo.Property.SetValue(v, newValue);
|
||||
|
Loading…
Reference in New Issue
Block a user