CSVHelper - Mapping CSV with variable header to object
<p>I'm trying to map some variable-format tab-separated files to my class, Foo:</p>

<pre><code>public class Foo
{
    public string A { get; set; }
    public int? B { get; set; }
    public double? C { get; set; }
}
</code></pre>

<p>File 1:</p>

<pre><code>A   B   C
string  1   1.0
</code></pre>

<p>File 2:</p>

<pre><code>Bee Sea
1   1.0
</code></pre>

<p>When the header format is constant, this is easy to do with CsvHelper using a CsvClassMap:</p>

<pre><code>public sealed class FooMap : CsvClassMap&lt;Foo&gt;
{
    public FooMap()
    {
        Map(x =&gt; x.A).Name("A");
        Map(x =&gt; x.B).Name("B");
        Map(x =&gt; x.C).Name("C");
    }
}
</code></pre>

<p>However, this becomes complex when the header format is variable.</p>

<ul>
<li>The files can vary in width and height.</li>
<li>Header order is not fixed.</li>
<li>A property is only defined a maximum of once per file.</li>
<li>Each property could relate to a variety of header names.</li>
<li>Header names are exclusive to a single property.</li>
<li>Not all properties are necessarily defined in a file.</li>
</ul>

<p>What would be the best way of mapping to this object?</p>

<p>I imagine I will be populating a mapping table for headers to properties with a unique key on the headers column, then looking up each header's respective property.</p>

<p>Current direction of investigation:</p>

<pre><code>public sealed class FooMap : CsvClassMap&lt;Foo&gt;
{
    public FooMap()
    {
    }

    public void SetHeaders(List&lt;string&gt; headers)
    {
        var dictionary = new Dictionary&lt;string, List&lt;string&gt;&gt;();
        dictionary.Add("A", new List&lt;string&gt;() { "A", "Aay" });
        dictionary.Add("B", new List&lt;string&gt;() { "B", "Bee" });
        dictionary.Add("C", new List&lt;string&gt;() { "C", "Sea" });

        ...

    }
}
</code></pre>