Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Filehelpers-在每个字段周围使用双引号导出,字段为空/null时除外_C#_Filehelpers - Fatal编程技术网

C# Filehelpers-在每个字段周围使用双引号导出,字段为空/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

我可能在搜索时漏掉了答案,但我有一个文件,需要所有字段都用双引号引起来,除非字段为空、缺失或null,然后只输入逗号

我正在使用
[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。这正是我在发现没有其他“本地”产品有效后所做的。