CsvWriter、CS1503 参数 2:无法转换 CultureInfo

CsvWriter, CS1503 Argument 2: cannot convert CultureInfo

我正在使用 CsvHelper(很棒的软件包,感谢 Josh),在使用 CultureInfo 时,.Net Core 的构造函数出现问题。

Josh 的例子有这样的东西...... (来自 https://joshclose.github.io/CsvHelper/examples/writing/write-class-objects

   using (var writer = new StreamWriter("path\to\file.csv"))
   using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
   {
      csv.WriteRecords(records);
   }

然而,这给了我,CS1503 参数 2:无法从 'System.Globalization.CultureInfo' 转换为 'CsvHelper.Configuration.Configuration'

所以,我需要改为这样做


using (var writer = new StreamWriter("path\to\file.csv"))
using (var csv = new CsvWriter(writer: writer  ))
   {
      csv.Configuration.CultureInfo = CultureInfo.InvariantCulture ; 
      csv.WriteRecords(records);
   }

Josh 的例子是错误的还是我做错了什么?

Josh 的示例适用于当前的 CsvHelper,版本 13.0.0

using (var writer = new StreamWriter("path\to\file.csv"))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
   csv.WriteRecords(records);
}

在版本 13.0.0 之前,您的示例有效。

using (var writer = new StreamWriter("path\to\file.csv"))
using (var csv = new CsvWriter(writer))
{
   csv.Configuration.CultureInfo = CultureInfo.InvariantCulture; 
   csv.WriteRecords(records);
}