C# Filehelpers-在每个字段周围使用双引号导出,字段为空/null时除外
我可能在搜索时漏掉了答案,但我有一个文件,需要所有字段都用双引号引起来,除非字段为空、缺失或null,然后只输入逗号 我正在使用C# Filehelpers-在每个字段周围使用双引号导出,字段为空/null时除外,c#,filehelpers,C#,Filehelpers,我可能在搜索时漏掉了答案,但我有一个文件,需要所有字段都用双引号引起来,除非字段为空、缺失或null,然后只输入逗号 我正在使用[FieldQuoted(“”,QuoteMode.AlwaysQuoted)]和以下输出示例: "Mary","Smith","555-555-5555","","1234","","3141 Pi Cr." 但我需要输出的结果是这样的: "Mary","Smith","555-555-5555",,"1234",,"3141 Pi Cr." 使用Filehelp
[FieldQuoted(“”,QuoteMode.AlwaysQuoted)]
和以下输出示例:
"Mary","Smith","555-555-5555","","1234","","3141 Pi Cr."
但我需要输出的结果是这样的:
"Mary","Smith","555-555-5555",,"1234",,"3141 Pi Cr."
使用Filehelpers有什么建议吗?您可以在写入文件之前使用事件修改输出
比如说
[DelimitedRecord(",")]
class Product : INotifyWrite // <-- implement events
{
[FieldQuoted(QuoteMode.AlwaysQuoted)]
public string Name;
[FieldQuoted(QuoteMode.AlwaysQuoted)]
public string Description;
[FieldQuoted(QuoteMode.AlwaysQuoted)]
public string Size;
public void BeforeWrite(BeforeWriteEventArgs e)
{
}
public void AfterWrite(AfterWriteEventArgs e)
{
// replace any occurrences of ,"", with ,,
e.RecordLine = e.RecordLine.Replace(",\"\",", ",,");
}
}
[分隔符记录(“,”)]
类产品:INotifyWrite//谢谢shamp00。这正是我在发现没有其他“本地”产品有效后所做的。