[英]How do I “go to definition” for the indexer `this[]` in Visual Studio
I work with a codebase where several classes implement an indexer :我使用一个代码库,其中有几个类实现了一个索引器:
public double this[int i, int j]
{
get { return ...; }
set { ...; }
}
When I stumble over code like foo[1,2] = 3
in visual Studio 2008, I frequently want to当我在 Visual Studio 2008 中偶然发现像
foo[1,2] = 3
这样的代码时,我经常想
right-click / "go to definition" , ie show the above definition in the visual studio editor window.右键单击/“转到定义” ,即在 Visual Studio 编辑器窗口中显示上述定义。
For normal properties or methods this works without problems:对于普通属性或方法,这可以毫无问题地工作:
foo.bar = 3
, right-click / "go to definition" takes me to the source code for foo.bar. foo.bar = 3
,右键单击/“转到定义”将我带到 foo.bar 的源代码。
For overloaded +
or ==
this works as well.对于重载的
+
或==
这也适用。
However with the indexer this does not seem to work.但是对于索引器,这似乎不起作用。 Is there any way to accomplish this?
有什么办法可以做到这一点吗?
(I cannot even search for the string "this[" in the appropriate source file, since the same syntax may be used throughout the class to access the indexer. I always have to scroll trough all the methods and properties in the dropdown list for this file) (我什至无法在适当的源文件中搜索字符串“this[”,因为可以在整个类中使用相同的语法来访问索引器。为此,我总是必须滚动下拉列表中的所有方法和属性文件)
This doesn't really help with 2008 of course, but in 2010 and above they have "fixed" this with the Navigate To command ( ctrl + , in the C# keyboard layout).当然,这对 2008 年并没有真正的帮助,但是在 2010 年及更高版本中,他们使用“导航到”命令( ctrl + ,在 C# 键盘布局中)“修复”了这个问题。 Where you can enter
this
to show a list of indexers in the current solution where you can double-click the one you want to navigate to.您可以在其中输入
this
以显示当前解决方案中的索引器列表,您可以在其中双击要导航到的索引器。
+1 for Resharper which seems to work fine with pressing F12 when you caret is within an indexer usage. +1 对于 Resharper,当您在索引器使用范围内使用插入符号时,按 F12 似乎可以正常工作。
您可以安装为您提供此功能的Resharper
,工具箱生产力不提供此功能
您最好的选择可能是转到foo
的定义并查看该类正在索引什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.