FileHelpers列标题

时间:2016-09-14 13:09:50

标签: filehelpers

简单的问题,因为我无法在任何地方找到它。如何为每列设置自定义列名?我尝试使用此功能:<FieldOrder(1), FieldTitle("Name")]>但它表示FieldTitle不存在。

1 个答案:

答案 0 :(得分:0)

它只会使用该字段的名称。

static void Main(string[] args)
{
    var j = 0;

    Func<int> calculateSomeValue = () =>
    {
        return 41;
    };

    Action myFoo = () =>
    {
        int i = calculateSomeValue() + j;
        j = i;
    };
}

输出:

[DelimitedRecord(",")]
class Product
{
    // Must specify FieldOrder too
    [FieldOrder(1)]
    public string Name;
    [FieldOrder(2)]
    public string Description;
    [FieldOrder(3)]
    public string Size;
}

class Program
{
    static void Main(string[] args)
    {
        var engine = new FileHelperEngine<Product>();
        engine.HeaderText = engine.GetFileHeader();

        var products = new Product[] { new Product() { Name = "Product", Description = "Some details", Size = "Large"} };
        var productRecords = engine.WriteString(products);

        Console.WriteLine(productRecords);
    }
}

如果你需要不同的东西,你可以做到

Name,Description,Size 
Product,Some details,Large

输出:

engine.HeaderText = "whatever,whatever,whatever";