在Metro中,获取(抽象)类的所有继承的类吗? [英] In metro, get all inherited classes of an (abstract) class?

查看:58
本文介绍了在Metro中,获取(抽象)类的所有继承的类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试获取Metro中的所有继承类时,我陷入了困境. WinRT API与.net框架不同,因此两种解决方案( solution1

I got stuck when trying to get all inherited classes in metro. The WinRT API is different from .net framework, so both the solutions (solution1 and solution2) don't work.

任何代码或工具解决方案都值得赞赏.

Any code or tool solution is appreciated.

我还在努力.如果成功,我将把解决方案放在这里.

I'm still trying. I will put my solution here if success.

推荐答案

这应该有效(基于此处):

public IEnumerable<T> GetEnumerableOfType<T>(params object[] constructorArgs) where T : class, IComparable<T>
{
    List<T> objects = new List<T>();
    foreach (Type type in typeof(T).GetTypeInfo().Assembly.ExportedTypes
                                   .Where(myType => myType.GetTypeInfo().IsClass && 
                                                    !myType.GetTypeInfo().IsAbstract && 
                                                    myType.GetTypeInfo().IsSubclassOf(typeof(T))))
    {
        objects.Add((T)Activator.CreateInstance(type, constructorArgs));
    }
    objects.Sort();
    return objects;
}

基本上TypeInfo现在是进行任何反射操作的主要类,您可以通过在Type上调用GetTypeInfo()来获取它.

Basically TypeInfo is now the main class for doing any reflection operations and you can get it by calling GetTypeInfo() on the Type.

这篇关于在Metro中,获取(抽象)类的所有继承的类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆