【问题标题】:Visual Studio Call Hierarchy : How to find calls through an implemented interface to a method?Visual Studio 调用层次结构:如何通过已实现的接口查找对方法的调用?
【发布时间】:2012-04-08 03:56:59
【问题描述】:

借助 Visual Studio 调用层次结构功能,我可以找到对某个方法的调用。

但是,它似乎无法通过已实现的接口找到类。如下所示,如果通过 IFoo 调用 Method(),那么在 Call Hierarchy 中找不到这些调用?

   interface IFoo
   {
       void Method();
   }

   class Foo : IFoo
   {
       public void Method() 
       {
           // ...
       }
   }

有没有办法在普通的 VS 中或使用一些免费插件来做到这一点?

Resharper 似乎能够做到这一点(在更复杂的情况下存在一些问题),如 C# - Can't find usage of method when inherited and used through an interface implemented by the subclass

br,图子

【问题讨论】:

  • 在提供的代码中,该类没有实现接口。这是一个错误吗?

标签: c# visual-studio-2010 code-navigation call-hierarchy


【解决方案1】:

嗯,我以前从未听说过调用层次结构;我总是在任何东西上使用 Find Symbol References - Shift + F12,包括方法名称。这会通过接口接听电话。

【讨论】:

  • 调用层次结构非常有用:Control-K + Control+T
【解决方案2】:

Reshaper 具有名为go to implementation 的功能。它允许您找到所有实现特定方法或接口的类。

它还有一个find usages。它可以根据您的需要从界面或直接从类中搜索用法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    相关资源
    最近更新 更多