Код: Выделить всё
private IEnumerable ProcessFile(string filePath) where Map : CsvHelper.Configuration.ClassMap, new()
{
LogInformation($"Processing file at {filePath}");
try
{
using var reader = new StreamReader(filePath);
using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
var records = csv.GetRecordsSafe();
LogInformation($"Successfully processed {records.Count()} records from {filePath}");
return records;
}
catch (Exception ex)
{
LogError($"Failed to process file at {filePath}: {ex.Message}");
return [];
}
}
Код: Выделить всё
public static IEnumerable GetRecordsSafe(this CsvHelper.CsvReader csvReader) where Map : CsvHelper.Configuration.ClassMap
{
try
{
csvReader.Context.RegisterClassMap();
return csvReader.GetRecords();
}
catch (CsvHelper.TypeConversion.TypeConverterException)
{
throw;
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ing-mapped
Мобильная версия