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

9
我正在尝试获取实现特定接口的类列表在Windows 8商店应用程序中,但是WinRT中反射似乎非常不同,到目前为止我还没有找到一个很好的示例。
有人知道如何加载当前程序集并遍历它吗?
非常感谢任何帮助 :)

你需要知道可以使用哪些类吗?因为这已经有很好的文档记录了。 - Security Hound
@Ramhound,我不太确定你在问什么,在我的场景中,我有100多个规则,每个规则都有一个唯一的名称并实现了IRule接口。我想获取所有实现IRule接口的类。 - Soroush Mirzaei
你看过这个线程了吗?也许它能帮到你。NG - Nelson Godinho
@NelsonGodinho 下面的答案完美地解决了问题,我会在明天标记它为答案。无论如何,谢谢 :) - Soroush Mirzaei
1个回答

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();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接