1

如何使用 DelimitedClassBuilder 动态执行此操作,以便文件中的列可以扩展但不会破坏我的程序?

[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);
4

1 回答 1

1

好问题。我能找到的最好的是:

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);

两者都应该工作。

于 2013-10-15T12:11:48.243 回答