C#、XmlDoc:如何引用方法重载

发布于 2024-08-02 03:22:35 字数 389 浏览 2 评论 0原文

如果我有这两种方法

public Foo Get(string bar) { ... }
public Foo Get(int bar) { ... }

并在不同的方法上编写这段 xml 文档,

/// <summary>
/// Has a close relation to the <see cref="Get"/> methods.
/// </summary>

我会在 Get 下看到一个蓝色波浪线,表示它是一个不明确的引用“Get”。 这是真的,但我希望它引用两者。 这样做的正确方法是什么? 或者我应该只引用单个方法重载?

If I have these two methods

public Foo Get(string bar) { ... }
public Foo Get(int bar) { ... }

And write this piece of xml documentation on a different method

/// <summary>
/// Has a close relation to the <see cref="Get"/> methods.
/// </summary>

I get a blue squiggly under Get, saying that it is an Ambiguous reference 'Get'. which is true, but I want it to reference both. What is the correct way of doing this? Or should am I only supposed to reference a single method overload?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦上情书 2024-08-09 03:22:35

尝试一下

/// Has a close relation to the <see cref="Get(string)"/>  
/// and <see cref="Get(int)" /> methods.

,您可能需要完整的类型名称,但只要您放入第一个括号,智能感知就会有所帮助。

希望有所帮助,

Try

/// Has a close relation to the <see cref="Get(string)"/>  
/// and <see cref="Get(int)" /> methods.

You may need full typenames but intellisense should help as soon as you put first bracket in.

Hope that helps,

Dan

皇甫轩 2024-08-09 03:22:35

这是这个老问题的更新答案。 我不确定这何时生效,因为没有太多文档。 如果您为 cref 属性添加 "o:..." 前缀,例如在 "o:myMethod()" 中,它将链接到重载部分并覆盖该方法的所有重载。 使用 Daniel Elliott 的答案示例:

/// Has a close relation to the <see cref="o:Get()"/> methods.  

这还将删除 Intellisense / Resharper 关于不明确引用的警告。

Here's an updated answer to this old question. I'm not sure when this became valid because there isn't much documentation out there. If you prefix a cref attribute with "o:..." such as in "o:myMethod()" it will link to the overload section and cover all of the overloads of that method. Using Daniel Elliott's answer's example:

/// Has a close relation to the <see cref="o:Get()"/> methods.  

This will also remove warnings from Intellisense / Resharper about ambiguous references.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文