I have the following scenario:
class Foo { }
class Foo<T> : Foo { }
And then two methods
void DoStuff(Foo foo)
{
DoStuffImpl(foo);
}
void DoStuffImpl(Foo foo)
{
Console.WriteLine("A");
}
void DoStuffImpl<T>(Foo<T> foo)
{
Console.WriteLine("B");
}
void Main()
{
DoStuff(new Foo<int>()); // prints A
}
(note, the code was written in the browser, but describes the situation I'm facing)
How can I get it to call the generic method, and print B?
Can this be done at all without reflection? I have some ideas on how it could be done with reflection, but I'm looking for a cleaner solution if one exists.
Note: I can't make DoStuff
generic because this will be used with WCF and open generic types are not allowed.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…