使用FileHelpers获取页眉和页脚

时间:2018-10-26 14:31:38

标签: c# filehelpers

我正在使用filehelpers打开固定文件,但是该文件具有页眉和页脚,我使用IgnoreFirst和IgnoreLast获取了文件中除它们之外的所有记录,但是我希望以某种方式获取它们,该怎么办?

    FileHelperEngine<InputRecord> engine_I = new FileHelperEngine<InputRecord>();
    List<InputRecord> input                = null;

    try
    {
        input              = engine_I.ReadFile(path).ToList();
        HeaderClass head   = //getheader
        FooterClass footer = //getfooter
    }
    catch (Exception ex)
    {
        // Erro treatments
    }

我的班级:

[IgnoreFirst(1)]
[IgnoreLast(1)]
[FixedLengthRecord()]
public class InputRecord
{
        [FieldFixedLength(1)]
        public string something1;


        [FieldFixedLength(20)]
        public string something2;


        [FieldFixedLength(8)]
        [FieldConverter(ConverterKind.Date, "yyyyMMdd")]
        public DateTime date1;


        [FieldFixedLength(8)]
        [FieldConverter(ConverterKind.Date, "yyyyMMdd")]
        public DateTime date2;

        [FieldFixedLength(24)]
        public string something3;
}

1 个答案:

答案 0 :(得分:0)

我建议可以使用FileEngine.BeforeReadRecordFileEngine.AfterReadRecord事件,如https://www.filehelpers.net/example/EventsAndNotification/ReadEvents/所示