简体   繁体   English

C#Metro风格的IsSubclassOf或IsAssignableFrom的任何替代方法

[英]Any alternative for IsSubclassOf or IsAssignableFrom in C# Metro-style

Is there any alternative for IsSubclassOf or IsAssignableFrom in C# Metro-style? C#Metro风格的IsSubclassOfIsAssignableFrom是否有其他替代方法?

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扩展方法来获取TypeTypeInfo实例:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM