[英]how to find a generic UI class in a list of different class without specifying the type?
你可以做的是:
var tabType = tab.GetType();
if (tabType.IsGenericType
&& typeof(DraggableLayout<>)
.IsAssignableFrom(tabType.GetGenericTypeDefinition()))
{ ... }
或者使用扩展方法:
public static bool IsOfGenericType(this Type source, Type genericType)
{
return source.IsGenericType
&& genericType.IsAssignableFrom(source.GetGenericTypeDefinition());
}
// ...
if (typeof(tab).IsOfGenericType(typeof(DraggableLayout<>)))
{ ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.