如何在中为方法重载创建 cref C# 中的标签?

发布于 2024-07-12 01:43:32 字数 270 浏览 10 评论 0原文

我在 MSDN 中看到诸如“CompareOrdinal Overloads”之类的链接。 我怎样才能用C#编写这样的链接?

我尝试过:

<seealso cref="MyMethod">MyMethod Overloads</seealso>

但是编译器向我发出警告,警告我对具有其他重载的方法的引用不明确。

(初学者问题:我实际上需要编写此标签来链接到重载,还是由文档处理器自动生成?)

I see in MSDN links such as "CompareOrdinal Overloads". How can I write such a link in C#?

I tried:

<seealso cref="MyMethod">MyMethod Overloads</seealso>

But the compiler gives me a warning about being an ambiguous reference for the method which has other overloads.

(Beginner question: do I actually need to write this tag to link to the overloads, or is it automatically generated by documentation processors?)

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

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

发布评论

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

评论(3

鹤舞 2024-07-19 01:43:32

要针对特定成员,我相信您只需匹配签名即可:

/// <seealso cref="Foo(int)"/>
static void Foo() { }
/// <seealso cref="Foo()"/>
/// <seealso cref="Foo(float)"/> <------ complains
static void Foo(int a) { }

说实话,我不确定如何生成“所有重载”链接; 我假设任何明智的生成器都会自动执行此操作。

To target specific members, I believe you just match the signature:

/// <seealso cref="Foo(int)"/>
static void Foo() { }
/// <seealso cref="Foo()"/>
/// <seealso cref="Foo(float)"/> <------ complains
static void Foo(int a) { }

To be honest, I'm not sure how to generate an "all overloads" link; I'd assume that any sensible generator did this automatically.

梦行七里 2024-07-19 01:43:32

使用Sandcastle很简单:

<seealso cref="overloads:FullyQualifiedMyMethod">MyMethod Overloads</seealso>

FullyQualifiedMyMethod是达到重载所需的完整路径,包括命名空间和类,即:System.Linq.Enumerable.Sum

但是VB编译器会发出警告,指出该属性无法解析,可以忽略。

Using Sandcastle it is simple:

<seealso cref="overloads:FullyQualifiedMyMethod">MyMethod Overloads</seealso>

FullyQualifiedMyMethod is the complete route you need to reach the overload, including namespaces and classes, i.e.: System.Linq.Enumerable.Sum

However VB compiler issues a warning saying the attribute can not be resolved, which can be ignored.

又爬满兰若 2024-07-19 01:43:32

Xml 文档没有办法引用方法的所有重载。

最流行的 C# 项目文档生成器是 Sandcastle。 如有必要,它将自动创建指向重载列表页面的链接。 因此,在成员列表页面中,重载方法的名称只会出现一次,单击它将导航到该方法的重载页面列表,并从那里导航到特定的重载。

在 Xml 文档中放置指向重载列表页面的链接需要对所使用的外部工具有深入的了解,这可能不是一个好主意。

如果您确实必须拥有这个,那么也许一种方法是使用具有特定形成的 ID 的锚点。 大多数文档生成器提供了一些对生成的文件进行预处理或后处理的神秘方法,并且应该让您有机会挑选出这些锚点并为它们提供适当的 href。

哦,这可能比它的价值更麻烦;)

Xml documentation doesn't have a means to reference all overloads of a method.

The most popular documentation generator for C# projects is Sandcastle. It will automatically create a link to an overloads list page if necessary. Hence in a members list page the name of an overloaded method will appear only once, clicking it will navigate you to the list of overloads page for that method and from there to a specific overload.

Placing a link to the overloads list page in Xml documentation would require intimate knowledge of the external tool being used and probably not a good idea.

If you really must have this then perhaps one way is to use an anchor with a specificaly formed ID. Most document generators provide some arcane means of pre or post processing generated files and should give you the opportunity to pick these anchors out and provide an appropriate href for them.

OTH, it may be more trouble than its worth ;)

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