假设我有一个固定长度的字符串:
ABBCCC10purple crayon5 red pencil9 green marker
A、B和C字段很容易映射:
[FixedLengthRecord] public class OutterRecord { [FieldFixedLength(1)] public string AField { get; set; } [FieldFixedLength(2)] public string BField { get; set; } [FieldFixedLength(3)] public string CField { get; set; } }
然而,该行的其余部分是一个对象数组。例如,假设10purple crayon
是:
[FixedLengthRecord] public class WritingInstrument { [FieldFixedLength(2)] public string Count { get; set; } [FieldFixedLength(7)] public string Color { get; set; } [FieldFixedLength(6)] public string TypeOfInstrument { get; set; } }
FileHelpers中是否有解析WritingIntstuments部分的方法?考虑到约束/限制,每个WritingInstrument记录的最大宽度为15个字符,数组中最多可以有10个项目。
我希望生成的反序列化对象如下所示:
[FixedLengthRecord] public class OutterRecord { [FieldFixedLength(1)] public string AField { get; set; } [FieldFixedLength(2)] public string BField { get; set; } [FieldFixedLength(3)] public string CField { get; set; } [SomeTypeOfFixedArray(10)] List<WritingInstrument> WritingInstruments { get; set; } }