Breaking down the MS RBTree (an internal .Net abstract class), I have discovered that one method returns TreePage<K>:
private TreePage<K> AllocPage(int size)
{
...
}
Within the method, variables are declared as TreePage…but the class is not defined that way:
private sealed class TreePage
{
...
}
Yet, when I mimic the code and definition using .Net 2010 (Express), I cannot do this:
Error: The non-generic type
‘RBTree.TreePage’ cannot be used
with type arguments
So, is there an extension method that I can’t find? Is there something MS is doing that we just don’t get to see?
When you declare a class nested in a generic class
this gets compiled to a class
and a class
Bar is generic, because it is nested in the generic class Foo. But the type parameter declaration is not repeated in C# (where you refer to the class as Foo<T>.Bar).
I noticed that Reflector shows the generic type parameter for classes nested in generic types, even if they don’t have declared any type parameters directly. That’s a bug. You need to fix the code when copy it straight out of Reflector.