如何快速找到接口方法的实现?
有没有一种快速方法可以找到接口的方法/属性/等的所有实现,而不是引用? 下面是一些示例代码:
public class SomeClass : IBaseClass
{
public Int32 GetInt()
{
return 1;
}
}
public interface IBaseClass
{
public Int32 GetInt();
}
public class SomeOtherClass
{
IBaseClass _someClass;
private TestMethod()
{
_someClass = new SomeClass();
_someClass.GetInt();
}
}
我想在查看 SomeOtherClass.TestMethod() 时快速访问 SomeClass.GetInt()。 如果我右键单击 _someClass.GetInt() 并单击“转到定义”,它将带我进入该界面。 如果我单击“查找所有引用”,我可能会看到所有用途的列表……而不仅仅是实现 GetInt() 方法的类。
有没有更快的方法来找到这个? 其他开发者有什么建议吗? 我们对大多数依赖项使用 DI,这意味着跟踪深度嵌套的代码需要永远。
Is there a quick way to find all of the implementations of, not references to, an interface's method/property/etc? Here's some sample code:
public class SomeClass : IBaseClass
{
public Int32 GetInt()
{
return 1;
}
}
public interface IBaseClass
{
public Int32 GetInt();
}
public class SomeOtherClass
{
IBaseClass _someClass;
private TestMethod()
{
_someClass = new SomeClass();
_someClass.GetInt();
}
}
I want to quickly get to SomeClass.GetInt() while reviewing SomeOtherClass.TestMethod(). If I right click on _someClass.GetInt() and click 'Go To Definition', it takes me to the interface. If I click 'Find All References', I could potentially see a list of all uses ... not just the classes that implement the GetInt() method.
Is there a faster way to find this? Any tips from other developers? We are using D.I. for most of our dependencies, which means that tracing through deeply nested code takes forever.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
由于我不喜欢在编码时使用鼠标,因此我通常
AFAIK,这是查找方法实现的最快方法,无需 ReSharper。
(顺便说一句:您可以使用相同的系统从类方法实现移动到相应的接口声明:只需选择根)
Since I don't like to use the mouse while coding, I usually
AFAIK this is the quickest way to find the implementation of a method, without ReSharper.
(By the way: you can use the same system to move from a class method implementation to the corresponding interface declaration: just select the root)
我相信 Alt-End 会在 ReSharper 中做到这一点。
Alt-End will do this in ReSharper, I believe.
如果没有 ReSharper,最好的方法是:
在文件中查找 (Ctrl+Shift+F)
查找内容:“class*ISomeClass”
查找选项:“使用通配符”
这将找到所有实现,然后您可以在具体实现中搜索您的函数。
Without ReSharper the best way to do this is:
Find in files (Ctrl+Shift+F)
Find What: "class*ISomeClass"
Find Options: "Use Wildcards"
This will find all implementation and than you can search for your function in a concrete implementation.
你可以尝试使用这个插件:
http://blog.rthand.com/post/2010/01/18/Meet-e2809cGo-To-Implementatore2809d-DXCore-plugin-for-Visual-Studio.aspx
you could try going with this plugin:
http://blog.rthand.com/post/2010/01/18/Meet-e2809cGo-To-Implementatore2809d-DXCore-plugin-for-Visual-Studio.aspx
如果您的界面与您通常想要导航到的具体模型位于同一库中,则可以向具体对象添加“使用别名”。 无论如何,“使用”都是帮助者,这很有帮助。
当您进入该界面时,您可以通过一种快速(但肮脏)的方式来获取界面的主要实现。 F12->F12!
If your interface is in the same library as your concrete model that you'll typically want to navigate to, you could add a 'using alias' to the concrete object. 'Usings' are helpers anyhow, and this helps.
When you're taken to the interface, you have a quick (and dirty) way of getting to the primary implementation of your interface. F12->F12!
R# 在弹出菜单上有一个“转到实现”选项,这非常方便。
R# has a Go to Implementation option on the pop-up menu, which is really handy for that.