有时候我想找出实现特定接口的所有标准的.NET类型的列表。通常它是出于好奇,有时也有一些实际的目的,(但是这不是问题的关键)。
我试图让这一点在MSDN的,但类型的页面只包含指向儿童的类型,而不是类型实现接口。
你知道有窍门如何做到这一点(或者一个工具,可以帮助)?
我写这篇code(的ICollection 的类型正在调查中):
VAR的结果= 从组装AppDomain.CurrentDomain.GetAssemblies()了ToList() 在assembly.GetTypes从类型() 其中,typeof运算(ICollection的).IsAssignableFrom(类型) 选择类型; 的foreach(在结果VAR型) { Console.Out.WriteLine(type.FullName); }
但是,这有一定的局限性:
感谢您的帮助!
解决方案它只搜索当前加载 组件。
总是有添加引用对话框,但你可能想看看这样一个问题:列出所有可用的.NET程序集的。
我无法想出一个办法做到这一点 对于通用接口(ICollection的<> 是行不通的)
试试这个查询,而不是:
从组件AppDomain.CurrentDomain.GetAssemblies() 在assembly.GetTypes从类型() 其中,type.GetInterfaces() 。任何(I => i.IsGenericType &功放;&安培; i.GetGenericTypeDefinition()== typeof运算(ICollection的<>)) 选择类型;
这将是很好,如果它提供的链接 MSDN的。
反射支持搜索类型的实施下,接口类型(选择派生类型 ),以及在搜索类型为MSDN文档(在类型单击鼠标右键,选择搜索MSDN)。
如果你不喜欢这个选项,你当然可以尝试编写的软件运行在MSDN上的Web搜索的类型的完全限定域名的东西。我不知道是否有任何元数据围绕映射一个类型的MSDN页面或实现这个目的的清洁方式。
Sometimes I want to find out a list of all standard .NET types that implement a specific interface. Usually it is out of curiosity, sometimes there is also some practical purpose (but that's not the point).
I tried to get this out of MSDN, but type's page only contains links children of types, not types implementing interface.
Do you know any trick how to do this (or a tool that would help)?
I wrote this code (ICollection is the type being investigated):
var result = from assembly in AppDomain.CurrentDomain.GetAssemblies().ToList() from type in assembly.GetTypes() where typeof(ICollection).IsAssignableFrom(type) select type; foreach (var type in result) { Console.Out.WriteLine(type.FullName); }But this has some limitations:
Thanks for help!
解决方案It only searches currently loaded assemblies.
There's always the "Add Reference" dialog, but you might want to look at the question: List all available .NET assemblies.
I couldn't figure out a way to do this for generic interfaces (ICollection<> wouldn't work)
Try this query instead:
from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.GetInterfaces() .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollection<>)) select type;
It would be nice if it provided links to MSDN.
.NET Reflector supports searching for types implementing an interface (choose "Derived Types" under a type) as well as searching MSDN for documentation on a type (right-click on a type and choose "Search MSDN").
If you don't like that option, you could of course try to write something that runs a web-search on MSDN with the type's full-qualified name. I'm unaware if there's any metadata around that maps a type to its MSDN page or a clean way of accomplishing that.
更多推荐
如何找出在基类库类型的列表实现特定的接口?
发布评论