[英]How to know the base type of an inherited generic type?
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. 当我查看AnotherType类型的BaseType属性时,它表示它是Object,我希望看到通用的MyClass类型。
Is there a way to know that AnotherClass inherits MyClass ? 有没有办法知道AnotherClass继承了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. 编辑 :问题是MyClass类型实际上是一个接口,所以它没有显示为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. 请发布失败的代码。
MyClass
是否真的是一个界面?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.