问题
When not running an application, pressing F12 (Go To Definition) on a method on an interface type will take you to the interface itself.
Is there any key combo that exists (or one that I can make) that will allow me to provide a default implementation to jump to, or allow me to quickly pick an implementation to go to?
We have several layers in our application, and it would save a lot of time to be able to jump straight to the Mock
or Real
implementations rather than navigating to them in source control.
回答1:
If using VS 2015 and above:
See answer below:
Visual Studio 2015 Update 1 added Edit.GoToImplementation which appeared in the context menu, but there was no keyboard shortcut associated with it by default.
In Visual Studio Update 2, we added a default shortcut of Ctrl+F12.
If using VS 2013 and below:
We had the same problem and started using Resharper. It has a nice Goto Implementation feature, which was working very well, as I remember.
The problem is that this tool is not free though (which is of course justified, as it offers much, much more than the mentioned feature).
Without this, I use Find All References and identify the implementation quickly by looking at the path (we have interfaces, implementations and mocks nicely segregated). But you've probably identified this possibility by yourself.
Also, you may consider an option mentioned in this answer (although it's for interface methods, not implementations):
- move the cursor over the method
- type CTRL+K CTRL+T to open the Call Hierarchy window
- move down to Implements node
- type Return to go to the selected implementation
回答2:
Visual Studio 2015 Update 1 added Edit.GoToImplementation which appeared in the context menu, but there was no keyboard shortcut associated with it by default.
In Visual Studio Update 2, we added a default shortcut of Ctrl+F12.
回答3:
Visual Studio 2015 has an "Edit.GoToImplementation" command that you can apply a keyboard shortcut to.
Tools / Options / Environment / Keyboard, then enter "Edit.GoToImplementation" into the show commands textbox. I use Shift+F12, so I change "Use new shortcut in" to Text Editor, then in "Press shortcut keys" I press Shift+F12 and click "Assign".
回答4:
Just press CTRL+F12 instead of just F12. This will take you directly to the implementation.
回答5:
If the keybinding is set and it is still not taking you to the implementation, make sure no other application has the same keybinding. In my case, CTRL+F12 was also used by DeskPins. Cost me a few minutes until I found it.
来源:https://stackoverflow.com/questions/32614752/f12-go-to-implementation-of-interface