Nested generics with IDictionary and IEnumerable
<p>In a generic C# class for an internal reusable library, I'd like to pass a reference to "something that maps to a list of other things". The data types of what is passed in there are not supposed to be known by the library. Also, the way they are stored should not be known either, i.e. what is today a list that is held in memory, might later be a database table that is read from on demand.</p>

<p>So I thought I'd write this library class:</p>

<pre><code>class GenericClass&lt;T, U&gt;
{
    public void Foo(IDictionary&lt;T, IEnumerable&lt;U&gt;&gt; bar)
    {
        // do something
    }
}
</code></pre>

<p>This compiles, but trying to pass in concrete implementations does not:</p>

<pre><code>class UsingClass
{
    public static void Main(string[] args)
    {
        var c = new GenericClass&lt;string, string&gt;();
        c.Foo(new Dictionary&lt;string, List&lt;string&gt;&gt;());
    }
}
</code></pre>

<p>I'm getting the following two syntax errors:</p>

<pre><code>Filename.cs(46,13): error CS1502: The best overloaded method match for 'GenericClass&lt;string,string&gt;.Foo(System.Collections.Generic.IDictionary&lt;string,System.Collections.Generic.IEnumerable&lt;string&gt;&gt;)' has some invalid arguments
Filename.cs(46,19): error CS1503: Argument 1: cannot convert from 'System.Collections.Generic.Dictionary&lt;string,System.Collections.Generic.List&lt;string&gt;&gt;' to 'System.Collections.Generic.IDictionary&lt;string,System.Collections.Generic.IEnumerable&lt;string&gt;&gt;'
</code></pre>

<p>Replacing the <code>IEnumerable</code> on the declaration of <code>Foo()</code> with <code>List</code> fixes it, but that's of course not quite what I want.</p>

<p>Is this really not supported by C# (4.0) or am I just missing something obvious? What workaround would you suggest? (I'm sure this has been talked about before a lot, so links to great descriptions are fine, too.)</p>

<p>Yes, I should be able to write my own helper classes for that, but why do I have to?</p>
