我知道我可以引用 csvhelper 中的所有字段使用以下类似内容,但如何仅在 Filehelpers 中引用所有字符串字段,您就有数据注释
csv助手有这样的东西
[Quoted]
public string mystring {get;set;}
void Main()
{
var records = new List<Foo>
{
new Foo { Id = 1, Name = "one" },
new Foo { Id = 2, Name = "two" },
};
using (var writer = new StringWriter())
using (var csv = new CsvWriter(writer))
{
csv.Configuration.ShouldQuote = (field, context) => true;
csv.WriteRecords(records);
writer.ToString().Dump();
}
}
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
最佳答案
根据this Github issue ,并补充说该功能被视为边缘情况而被考虑并被拒绝。
为了实现您的目标,您可以编写自己的转换器来根据需要处理这些字段。如果您这样做,请注意该 Github 问题中有关 Configuration.QuoteNoFields = true
的注释。
有一个示例类型转换器 here
关于c# - 仅引用 csvhelper 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57342592/