|
@@ -38,16 +38,23 @@ public class ExcelReader : IDisposable
|
|
|
var property = type.GetProperty(item.PropertyName);
|
|
|
if (property == null) continue;
|
|
|
|
|
|
- if (property.PropertyType.BaseType == typeof(SpecialBase) &&
|
|
|
- RuntimeHelpers.GetUninitializedObject(property.PropertyType) is SpecialBase special)
|
|
|
+ try
|
|
|
{
|
|
|
- special.GetValueFromCell(cell);
|
|
|
+ if (property.PropertyType.BaseType == typeof(SpecialBase) &&
|
|
|
+ RuntimeHelpers.GetUninitializedObject(property.PropertyType) is SpecialBase special)
|
|
|
+ {
|
|
|
+ special.GetValueFromCell(cell);
|
|
|
|
|
|
- property.SetValue(current, special);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ property.SetValue(current, special);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- current.SetPropertyValue(property, cell.Value);
|
|
|
+ current.SetPropertyValue(property, cell.Value);
|
|
|
+ }
|
|
|
+ catch (ArgumentException e)
|
|
|
+ {
|
|
|
+ throw new ArgumentException($"{e.Message}\nLocation: {cell.Address.ColumnLetter}{cell.Address.RowNumber} ({cell.Worksheet.Name})", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
yield return current;
|
|
@@ -103,11 +110,7 @@ public class ExcelReader : IDisposable
|
|
|
|
|
|
public IEnumerable<T> ReadAll<T>(uint startFrom = 1, uint skip = 0) where T : class
|
|
|
{
|
|
|
- foreach (var worksheet in xlWorkbook.Worksheets)
|
|
|
- {
|
|
|
- foreach (var item in Read<T>(worksheet, startFrom, skip))
|
|
|
- yield return item;
|
|
|
- }
|
|
|
+ return xlWorkbook.Worksheets.SelectMany(worksheet => Read<T>(worksheet, startFrom, skip));
|
|
|
}
|
|
|
|
|
|
public void Dispose()
|
|
@@ -120,7 +123,7 @@ public class ExcelReader : IDisposable
|
|
|
{
|
|
|
if (disposing)
|
|
|
{
|
|
|
- xlWorkbook?.Dispose();
|
|
|
+ xlWorkbook.Dispose();
|
|
|
}
|
|
|
}
|
|
|
~ExcelReader() => Dispose(false);
|