如何找出在基类库类型的列表实现特定的接口?

编程入门 行业动态 更新时间:2024-10-19 08:58:05
本文介绍了如何找出在基类库类型的列表实现特定的接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有时候我想找出实现特定接口的所有标准的.NET类型的列表。通常它是出于好奇,有时也有一些实际的目的,(但是这不是问题的关键)。

我试图让这一点在MSDN的,但类型的页面只包含指向儿童的类型,而不是类型实现接口。

你知道有窍门如何做到这一点(或者一个工具,可以帮助)?

我写这篇code(的ICollection 的类型正在调查中):

VAR的结果=             从组装AppDomain.CurrentDomain.GetAssemblies()了ToList()             在assembly.GetTypes从类型()             其中,typeof运算(ICollection的).IsAssignableFrom(类型)             选择类型;         的foreach(在结果VAR型)         {             Console.Out.WriteLine(type.FullName);         }

但是,这有一定的局限性:

  • 只搜索当前加载的程序集。
  • 在我无法想出一个办法做到这一点的通用接口(的ICollection<> 是行不通的)。
  • 这将是很好,如果它提供的链接,MSDN(但我客串,可能是固定的)。
  • 感谢您的帮助!

    解决方案   

    它只搜索当前加载   组件。

    总是有添加引用对话框,但你可能想看看这样一个问题:列出所有可用的.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:

  • It only searches currently loaded assemblies.
  • I couldn't figure out a way to do this for generic interfaces (ICollection<> wouldn't work).
  • It would be nice if it provided links to MSDN (but I gues that could be fixed).
  • 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.

    更多推荐

    如何找出在基类库类型的列表实现特定的接口?

    本文发布于:2023-11-09 20:51:41,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1573402.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:出在   类库   接口   类型   列表

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!