是否有可能检查泛型类型,而不使用任何泛型参数?
例如,我想能够执行类似于以下操作(实际类型名称已更改以保护隐私):
var list = new List<SomeType>();
...
if (list is List)
{
Console.WriteLine("That is a generic list!");
}
上述代码当前生成以下错误:
Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments
有什么解决方法吗?最好是简洁的,适用于没有泛型参数的类型(例如:“如果myString是List”)的方法。