[英]Any alternative for IsSubclassOf or IsAssignableFrom in C# Metro-style
Is there any alternative for IsSubclassOf
or IsAssignableFrom
in C# Metro-style? C#Metro风格的
IsSubclassOf
或IsAssignableFrom
是否有其他替代方法?
I'm trying to make this code run on Metro but can't find alternative. 我正在尝试使此代码在Metro上运行,但找不到替代方法。
if ((ui.GetType() == type) || (ui.GetType().IsSubclassOf(type)))
{
return true;
}
Many of the reflection methods can be found in the System.Reflection.TypeInfo
class. 在
System.Reflection.TypeInfo
类中可以找到许多反射方法。
You can get an instance of TypeInfo
for your Type
using the GetTypeInfo
extension method, provided by System.Reflection.IntrospectionExtensions
: 您可以使用由
System.Reflection.IntrospectionExtensions
提供的GetTypeInfo
扩展方法来获取Type
的TypeInfo
实例:
using System.Reflection;
// ...
ui.GetType().GetTypeInfo().IsSubclassOf(type)
You can use this: 您可以使用此:
using System.Reflection;
// ...
ui.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());
This works in Metro. 这适用于Metro。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.