Function with derived type parameter in a dictionary with the Type as the Key
<p>I want to be able to store a function in a dictionary with the Key being the object type.  All functions will accept objects derived from the same base class.  I want to be able to convert (based on a registered function) a class into a DbCommand. I've listed my code below in the form that seems correct but something is wrong with the syntax, etc.  I think I'm missing something really simple... Any help will be greatly appreciated!</p>

<pre><code>private Dictionary&lt;object, Func&lt;TrackingRecord, DbCommand&gt;&gt; conversionFunctions = new Dictionary&lt;object, Func&lt;TrackingRecord, DbCommand&gt;&gt;();


public void RegisterConversionFunction&lt;T&gt;(Func&lt;T, DbCommand&gt; conversionFunction) where T : TrackingRecord
    {
        conversionFunctions.Add(typeof(T), conversionFunction);
    }

public DbCommand GetConverstion&lt;T&gt;(T trackingRecord) where T : TrackingRecord
    {
        DbCommand command = null;

        if (conversionFunctions.ContainsKey(trackingRecord.GetType()))
        {
            Func&lt;T, DbCommand&gt; conversionFunction;
            if (conversionFunctions.TryGetValue(trackingRecord.GetType(), out conversionFunction))
            {
                command = conversionFunction.Invoke(trackingRecord);
            }
        }
        else
        {
            command = DefaultConversion(trackingRecord);
        }
        return command;
    }
</code></pre>
