确定 C# 中定义函数的位置?
我是 C# 的新手(我以前从未使用过它),最近需要查看用它编写的一些代码。我花了最长的时间试图追踪一个类中不存在的方法,该方法似乎在使用它的类中的任何地方都没有定义。后来我发现这是一种“扩展方法”,我认为这是一种通过某些来源移植到另一个类上的方法。
我完全理解这个语言功能背后的基本原理,并且实际上认为它非常好。然而,对于没有太多语言经验的人来说,查找不熟悉的方法变得更加困难,因为有问题的方法可以在任何地方定义。
我的问题是这样的:考虑到 C# 中的一个不熟悉的方法调用,考虑到它可能是在完全独立的类中定义的扩展方法,那么我查找更多信息的最佳方法是什么?
I am a complete novice at C# (I've never used it before) and recently needed to look over some code written in it. I spent the longest time trying to track down a nonexistent method in a class that didn't seem to be defined anywhere in the class that was using it. I later found out it was an "extension method," which I gather is a method grafted onto another class by some source.
I completely understand the rationale behind this language feature and actually think it's quite nice. However, as someone without much experience in the language, it makes it harder to look up unfamiliar methods, since the method in question could be defined anywhere.
My question is this: given an unfamiliar method call in C#, what's the best way for me to look up more info on it, given that it could be an extension method defined in an entirely separate class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我只需右键单击该函数并选择“转到定义”。
I would simply right-click the function and select "Goto definition".
在标准 C# 环境键集上:
F12
:转到定义Cntrl + -(Minus)
:返回到上一个鼠标位置(基本上返回到之前的位置) )On the standard C# environment key set:
F12
: Go to definitionCntrl + -(Minus)
: Go back to the last mouse position (basically go back to where you were before)您想要什么样的信息?如果是框架中定义的常规扩展,您可以在 msdn 上搜索信息。除此之外,我还推荐 Uwe Keim 编写的解决方案,右键单击并选择“转到定义”。
What kind of information do you want? If it regular extension that are defined in the framework you can search information on msdn. Except for that I also recommend the solution that Uwe Keim wrote, right click and select "Goto definition".