有没有一种方法,导航至某个接口的方法背后的真正落实?方法、接口

2023-09-02 12:01:04 作者:悠然自得。

在Visual Studio中,当你右键点击一个方法调用,你到那个方法的类,除非你通过一个接口来访问这个方法里面实现:在这种情况下你去接口方法不实际实施

In Visual Studio, when you right-click a method call, you go to the implementation of that method inside a class except if you access this method through an interface: in that case you go to the interface method not to the actual implementation.

有没有一种方法/技巧(快捷键或任何东西)来访问这个实际执行?否则,你被卡住添加一些评论只是要记住,你做了实现它,这真的不是生产,而且容易出错!

Is there a way / tips (key shortcut or anything) to access this actual implementation ? Otherwise you are stuck to add some comment just to remember where you did implement it that's really not productive and error prone !

更新:有趣的答案,但我不是很满意,因为所有的都是繁琐。我会以precise例如:

Update: interesting answers but I'm not really satisfied because all are cumbersome. I will give a precise example:

IInterface iInterface = someObject;                        
iInterface.someMethod();

其实,如果Visual Studio的只是一点点聪明,看起来就像一条线上面的方法调用它会看到是真正的对象。这将节省我很多的按键,并避免使用查找所有引用,然后用我的疲惫的眼睛扫描线,看看哪条线路包含正确的:)

Actually if Visual Studio was just a little bit clever to look just one line above the method call it would see where's the real object is. And that would save me a lot of keystrokes and avoid to use "find all references" and then scan the lines with my tired eyes to see which line contain the right one :)

推荐答案

我做到以下几点:

1),右键单击方法调用并单击转到定义(或者只是把光标放在它和命中F12)。这将带你到接口声明

1) Right click on the method call and click "Go to definition" (or just put the cursor on it and hit F12). That will take you to the interface declaration

2)右击接口方法声明,然后单击查看调用层次(或快捷键Ctrl + K,Ctrl + T键)

2) Right click on the interface method declaration and click "View call hierarchy" (or shortcut Ctrl+K, Ctrl+T)

3)展开器具X文件夹,将随后向你展示方法的所有实现。点击一去那里。

3) Expand the "Implements x" folder which will then show you all the implementations of that method. Click on one to go there.

相对快速和容易。烦人虽然似乎没有成为一个等效接口本身

Relatively quick and easy. Annoyingly though there doesn't seem to be an equivalent for the interface itself.

 
精彩推荐
图片推荐