在C#中没有使用Filehelpers FileHelperAsyncEngine的头文件

时间:2016-03-10 11:50:12

标签: c# header filehelpers

从FileHelperEngine切换到FileHelperAsyncEngine后,似乎无法让FileHelpers库写入标头。我根据文档调用了GetFileHeader()。有任何想法吗?

<!-- language: c# -->

var engine = new FileHelperAsyncEngine<ClaimModel>();
using (engine.BeginWriteFile(file))
{
    engine.HeaderText = engine.GetFileHeader();
    foreach (ClaimModel claim in claims)
    {
        engine.WriteNext(Utils.CleanStrings(claim));
    }
 }

   [FileHelpers.DelimitedRecord("|")]
    public class ClaimModel : Model
    {
        [FieldQuoted()]
        public string PolicyRef ;

1 个答案:

答案 0 :(得分:3)

您需要在HeaderText之前设置BeginWriteFile()

var engine = new FileHelperAsyncEngine<ClaimModel>();
engine.HeaderText = engine.GetFileHeader();
using (engine.BeginWriteFile(file))
{
    foreach (ClaimModel claim in claims)
    {
        engine.WriteNext(Utils.CleanStrings(claim));
    }
}