使用 FileHelpers DelimitClassBuilder 添加数组字段
本文关键字:数组 字段 添加 DelimitClassBuilder FileHelpers 使用 | 更新日期: 2023-09-27 18:35:20
如何使用 DelimitClassBuilder 动态执行此操作,以便文件中的列可以扩展但不破坏我的程序?
[DelimitedRecord(",")]
public class MyRecord
{
public string Name;
[FieldOptional, FieldArrayLength(0, 100)]
public string[] I_DONT_CARE_WHAT_COMES_AFTER_THIS;
}
即我如何完成此操作:
var cb = new DelimitedClassBuilder("xyz", ",");
cb.AddField("Name", "string");
... how do I add the array field here?
Type type = cb.CreateRecordClass();
var engine = new DelimitedFileEngine(type);
好问题。我能找到的最好的是:
var cb = new DelimitedClassBuilder("xyz", ",");
cb.AddField("Name", "string");
cb.AddFields(100);
foreach (var field in cb.Fields.Where(f => f.FieldName.StartsWith("Field")))
{
field.FieldOptional = true;
}
var type = cb.CreateRecordClass();
var engine = new DelimitedFileEngine(type);
我无法让它工作
cb.AddField("I_DONT_CARE", typeof(string[]));
也不与
cb.AddField("I_DONT_CARE", typeof(string[]).FullName);
两者都应该有效。