简体   繁体   English

如何在 Visual Studio 中为索引器“this[]”“转到定义”

[英]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.

相关问题 如何在Visual Studio中以编程方式执行“转到定义”? - How can I perform “Go To Definition” programmatically in Visual Studio? 在Visual Studio中是否与“转到定义”相反? - Is there an opposite to 'go to definition' in Visual Studio? 转到定义并查找所有引用在Visual Studio中不起作用 - Go to definition & Find all references do not work in Visual Studio 如何在Visual Studio 2010中将“对象浏览器”变为“转到定义”的“元数据”? - How can I turn “Object Browser” to “Metadata” for “Go to definition” in Visual Studio 2010? 转到Visual Studio中的覆盖方法定义 - Go to override method definition in Visual Studio Visual Studio 2019 进入定义状态,Intellisense 不起作用 - Visual studio 2019 go to definition and Intellisense not working 当按F12进入Visual Studio 2015 / C#中的定义时出现错误 - I got error when press F12 Go to definition in Visual Studio 2015 / C# 如何隐藏<summary>在 Visual Studio 代码中按 F12(转到定义)时的 [元数据]</summary> - How to hide <summary> in [metadata] when press F12 (Go to definition) in visual studio code 如何找到数组中最大的索引器 - How do i find the largest indexer in an array Intellisense显示错误,无法“定义”(Visual Studio 2013) - Intellisense showing false errors, cannot “go to definition” (Visual Studio 2013)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM