用filehelper填充零
本文关键字:填充 filehelper | 更新日期: 2023-09-27 18:05:58
我使用FileHelpers来创建NACHA文件。在下面的示例
许多属性都是带有前导零的数字,因此它们被定义为字符串。是否有一个属性可以填充Class属性中的前导零,类似于FieldTrim/TrimMode
的工作方式来删除空白?
[FixedLengthRecord()]
public class FileControlRecord
{
[FieldFixedLength(1)]
public int RecordTypeCode = 9; //Constant
[FieldFixedLength(6)]
public string BatchCount; //Numeric
[FieldFixedLength(6)]
public string BlockCount; //Numeric
[FieldFixedLength(8)]
public string EntryAddendaCount; //Numeric
[FieldFixedLength(10)]
public string EntryHash; //Numeric
[FieldFixedLength(12)]
public string TotalDebit; //$$$$$$$$$$cc
[FieldFixedLength(12)]
public string TotalCredit; //$$$$$$$$$$cc
[FieldFixedLength(39)]
[FieldNotInFile]
public string RESERVED; //Blank
}
必须使用FieldAlign来填充char:
[FixedLengthRecord()]
public class FileControlRecord
{
[FieldFixedLength(1)]
public int RecordTypeCode = 9; //Constant
[FieldFixedLength(6)]
public string BatchCount; //Numeric
[FieldFixedLength(6)]
public string BlockCount; //Numeric
[FieldFixedLength(8)]
public string EntryAddendaCount; //Numeric
[FieldFixedLength(10)]
public string EntryHash; //Numeric
[FieldFixedLength(12)]
[FieldAlign(AlignMode.Right, '$')]
public string TotalDebit; //$$$$$$$$$$cc
[FieldFixedLength(12)]
[FieldAlign(AlignMode.Right, '$')]
public string TotalCredit; //$$$$$$$$$$cc
[FieldFixedLength(39)]
public string RESERVED; //Blank
}
PS:我建议你使用最新版本的库:
https://github.com/MarcosMeli/FileHelpers/releases/latest或通过NuGet https://www.nuget.org/packages/FileHelpers/