views:

81

answers:

2

Consider this code :

class MyClass<T>
{
}

class AnotherClass : MyClass<String>
{
}

When I look at the BaseType property of the AnotherType Type, it says that it is Object, where I expected to see the generic MyClass type.

Is there a way to know that AnotherClass inherits MyClass ?

EDIT : The problem was that the MyClass type was actually an interface, so it is totally normal that it is not shown as BaseType.

+8  A: 

Unable to reproduce:

using System;

class MyClass<T> {}
class AnotherClass : MyClass<string> {}

public class Test
{
    static void Main()
    {
        // Prints MyClass`1[String]
        Console.WriteLine(typeof(AnotherClass).BaseType);
    }
}

Please post the code that's failing.

Jon Skeet
+1, same conclusion here :-)
Darin Dimitrov
I'm using Assembly.GetExecutingAssembly().GetTypes() when trying to get the BaseType, could it be the source of the problem ?
Thibault Falise
@T.Falise: It's hard to say without knowing how you're using it. A short but complete program which demonstrates the problem would make it a lot clearer.
Jon Skeet
Found the problem, I didn't see the "MyClass" was an interface, read my colleague code a bit too fast ... Thanks for the answers anyway !
Thibault Falise
+1  A: 

Is there any chance that MyClass is actually an interface?

Anton Gogolev
Yes, it was actually the real problem, I edited the question to include my misreading
Thibault Falise