问题描述
通常,当浏览代码时,我会遇到这样的:
Oftentimes when browsing code, I'll come across something like this:
public class Fruity
{
private IOrange _Orange;
public Fruity()
{
_Orange = new Orange() as IOrange;
}
public void PrepareFruit()
{
return _Orange.Peel();
}
}
很好,所以现在我想看看Peel方法。右键单击该方法,让我转到定义,它带我到接口存根。
Great, so now I want to see how the Peel method is implemented. Right-clicking on the method gives me Go To Definition which takes me to the interface stub.
确实,严格来说,定义是由接口给出的,私有变量是以这种方式定义的,但是有什么方法去实现?
OK, strictly speaking, the definition is ascribed by the interface given that the private variable is defined in this way, but is there any way to just go to the implementation?
当然有查找所有引用,这是一个分散枪调用,接口和结构的方法。但是在这种情况下,实现的源是明显的,所以我应该能够跳到它,我会想...
There is of course Find All References which is a scatter-gun approach of calls, interfaces and concretions. But the source of the implementation is obvious in this case so I should be able to jump to it I'd have thought...
显然,有时会有歧义这在这里很好地描述:
Evidently, there can sometimes be ambiguity which is described nicely here:
但是当实现非常清楚时,应该有一个Go To Implementation选项。
But surely, there should be a Go To Implementation option when the implementation is crystal clear.
推荐答案
您将得到导航到符号窗口,其将列出实际实现,通常作为第二项。它是关于没有第三方工具找到它的最快的方式。与查找所有引用不同,它只显示方法定义,而不是调用它的任何地方。
If you double-click or highlight Peel
and press CTRL+,
you'll get the "navigate to symbol" window which will list the actual implementation, usually as the second item. It's about the fastest way of finding it without 3rd party tools. And unlike "find all references", it only shows the method definitions and not wherever it's called.
这篇关于转到实现的方法而不是接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!