C# Dynamic Invoking
<p>Good Day,</p>

<p>I have a situation where I'm using code that contains a class called ImportFileContext.  The code looks like:</p>

<pre><code>// One of 5 different types can be passed in
public AddImportData(CustomType ModelData)
{
    // Depending on which 5 different types, the formatted type will change
    FormattedType data = ConvertModelDataToFormattedData(ModelData);
    using (var db = new ImportFileContext())
    {
        // Can this next line be made dynamic?
        db.ImportFormattedData.Add(data);
        db.SaveChanges();
    }
}
</code></pre>

<p>Basically, a CustomType will always be passed in to the method.  However, there are five different custom types that can be passed in.  Depending on which 5 can be passed in, the data will be modified.</p>

<p>Use cases:</p>

<ol>
<li>Custom Type passed in, format data to a specific format, then add that item to 
List of the db instance.</li>
<li>Custom Type 2 passed in, format data to a specific format, then add that item to
List of the db instance.</li>
<li>Custom Type 3 passed in, format data to a specific format, then add that item to 
List of the db instance.</li>
</ol>

<p>So what I'm looking for is a way add an item to the List depending on the data type without having to write several different methods to test which type I'm receiving then adding the item.  I know of the strategy pattern and I could use that, but what about adding an item to a list?</p>

<p>I'm really trying to avoid writing code that would look like:</p>

<pre><code>// One of 5 different types can be passed in
public AddImportData(CustomType ModelData)
{
    // Depending on which 5 different types, the formatted type will change
    FormattedType data = ConvertModelDataToFormattedData(ModelData);
    using (var db = new ImportFileContext())
    {
        if (typeof(ModelData) == "CustomType")
            db.ImportFormattedData.Add(data);
        elseif (typeof(ModelData) == "CustomType1")
            db.ImportCsvData.Add(data);
        elseif (typeof(ModelData) == "CustomType2")
            db.ImportTabDelimetedData.Add(data);
        db.SaveChanges();
    }
}
</code></pre>

<p>TIA,</p>

<p>coson</p>
