Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,12 @@ protected virtual void ParseData(ExcelPackage excelPackage)
SetValue(cell, dataItem, propertyInfo, value);
continue;
}
// 如果是可空枚举,选中空白项传入"",处理成null,不然会出现SetValue会报错
else if (propertyInfo.PropertyType.IsNullable() && propertyInfo.PropertyType.GetNullableUnderlyingType().IsEnum)
{
SetValue(cell,dataItem,propertyInfo,null);
continue;
}
}

if (propertyInfo.PropertyType.IsEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,5 +1210,12 @@ public async Task Issue377_Test()
import.HasError.ShouldBeFalse();
import.Data.Count.ShouldBe(3);
}
[Fact(DisplayName = "可空枚举类型导入测试")]
public async Task NullableEnum_Test()
{
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "Import", "NullableEnum.xlsx");
var import = await Importer.Import<NullableEnumTestImportDto>(filePath);
import.HasError.ShouldBeFalse();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Magicodes.ExporterAndImporter.Core;

namespace Magicodes.IE.Tests.Models.Import;
/// <summary>
/// 可空枚举问题测试
/// </summary>
public class NullableEnumTestImportDto
{
/// <summary>
/// 编号
/// </summary>
[ImporterHeader(Name = "编号")]
public string No { get; set; }
/// <summary>
/// 等级
/// </summary>
[ImporterHeader(Name = "等级")]
public EnumTest? Level { get; set; }
}
public enum EnumTest
{
A,
B,
}
Binary file not shown.
Loading