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