开发者

How to know the base type of an inherited generic type?

开发者 https://www.devze.com 2022-12-24 13:49 出处:网络
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 expe

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 开发者_StackOverflow社区the MyClass type was actually an interface, so it is totally normal that it is not shown as BaseType.


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.


Is there any chance that MyClass is actually an interface?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号