你如何找到一个接口的所有实现? [英] How do you find all implementations of an interface?

查看:1396
本文介绍了你如何找到一个接口的所有实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有在C#中定义的接口。什么是找到提供接口的实现所有类最简单的方法?

Suppose you have an interface defined in C#. What is the easiest method to find all classes that provide an implementation of the interface?

蛮力的方法是使用查找参考在Visual Studio和手动通过结果看,从实现中分离出来的惯例,但对于一个大codeBase的一个接口,在很大程度上的参考的相对较少的实现方式中,这可能是耗时的并且容易出错。

The brute force method would be to use "Find References" in Visual Studio and manually look through the results to separate out the usages from the implementations, but for an interface in a large codebase that is heavily referenced with relatively few implementations, this can be time consuming and error prone.

在Java中,在codeBase类(使用 - 私人选项包括私有类)的javadoc运行会产生对接口的文档页面(如的可比),它包括了所有的接口实现类以及任何子接口(虽然它不包括子接口的实现类,这些都是比较容易地确定通过钻孔向下进入列出子接口)。正是这种功能,我在寻找,但与C#和Visual Studio。

In Java, running javadoc on the codebase (using the -private option to include private classes) would generate a documentation page for the interface (e.g. Comparable) that includes all implementing classes for the interface as well as any subinterfaces (though it doesn't include implementing classes of the subinterfaces, these are relatively easy to determine by drilling down into the listed subinterfaces). It's this functionality that I'm looking for but with C# and Visual Studio.

推荐答案

(编辑基于评论...)

(Edit based on comment...)

如果您有ReSharper的安装:

在Visual Studio中,右键单击类型名称,然后选择转到继承者。或者,选择该类型名称,然后到ReSharper的/视图/类型层次开辟一个新的标签。 (菜单会显示您的键盘快捷键 - 这可能会有所不同,这就是为什么我解释了如何找到它:)

In Visual Studio, right click on the type name and choose "Go to Inheritor". Alternatively, select the type name, then go to ReSharper/View/Type Hierarchy to open up a new tab. (The menu will show you the keyboard shortcut - this can vary, which is why I explained how to find it :)

如果您没有ReSharper的:


  • 您可以使用反射,这是能够非常向你展示所有类型层次容易 - 只需根据类型名称是基本类型和派生类型扩展项目。类似的工具可用,如 ILSpy 并的 dotPeek

  • 购买ReSharper的 - 这是一个伟大的工具:)

  • You can use Reflector, which is able to show you all the type hierarchy very easily - just under the type name are expandable items for base types and derived types. Similar tools are available such as ILSpy and dotPeek.
  • Buy ReSharper - it's a great tool :)

这篇关于你如何找到一个接口的所有实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆