我正在使用 FileHelpers 将一些数据写入 CSV 文件。FileHelpers 很棒,因为它让我可以使用 FileHelper 转换器轻松格式化各种字段。以下是 FileHelpers DelimitedRecord 的示例:
[DelimitedRecord(",")]
public class ShippedRecord
{
public string Customer;
#quouted as can contain ',' characters
[FieldQuoted]
public string Address;
[FieldConverter(ConverterKind.Date, "yyyy-MM-dd")]
public DateTime ShippedDate;
[FieldConverter(ConverterKind.Date, "yyyy-MM-dd")]
public DateTime ReceivedDate;
public string DaysTillDelivery;
public string DeliveryStatus;
}
我希望用户能够通过配置文件指定他们希望将哪些字段写入 CSV 文件。使用 FileHelpers,如何动态更改写入 CSV 文件的字段?我知道我可能会使用 DataTable 之类的东西,但我不确定如何格式化字段(引用值、日期格式等),如果可能的话,我更喜欢使用 FileHelpers 提供的简单转换器。如果不可能,我该如何根据上面的示例记录使用 DataTable 格式化字段?