获取在WinRT中实现给定接口的所有类

Sor*_*aei 9 c# reflection windows-8 windows-runtime windows-store-apps

我正在尝试获取在Windows 8商店应用程序中实现某个界面的类列表,但似乎WinRT中的反射非常不同,到目前为止我找不到这样做的好例子.

有谁知道,如何加载当前的程序集并循环它?

任何帮助深表感谢 :)

Sor*_*aei 11

得到了MSDN论坛的答案.只需在此处发布,以防其他人正在寻找同样的事情.

此代码将获取实现IDisposable接口的所有类:

// We get the current assembly through the current class
var currentAssembly = this.GetType().GetTypeInfo().Assembly;

// we filter the defined classes according to the interfaces they implement
var iDisposableAssemblies = currentAssembly.DefinedTypes.Where(type => type.ImplementedInterfaces.Any(inter => inter == typeof(IDisposable))).ToList();
Run Code Online (Sandbox Code Playgroud)