XML 注释——如何正确注释显式实现的接口?

发布于 2024-11-07 01:41:03 字数 646 浏览 0 评论 0原文

代码:

public interface IFoo
{
    void Bar();
}

public class FooClass : IFoo
{
    /// <summary> ... </summary>
    /// <seealso cref="?"/> //How do you reference the IFoo.Bar() method
    public void Bar() { }

    /// <summary> ... </summary>
    /// <seealso cref="?"/> //How do you reference the standard Bar() method
    void IFoo.Bar() { }
}

我的猜测是:

<seealso cref="IFoo.Bar()"/> //Explicitly implemented interface method
<seealso cref="Bar()"/>      //Standard method

但是,我不确定。 ECMA 指南没有帮助区分,所以我想我正在寻找我的猜测是否正确的保证。

Code:

public interface IFoo
{
    void Bar();
}

public class FooClass : IFoo
{
    /// <summary> ... </summary>
    /// <seealso cref="?"/> //How do you reference the IFoo.Bar() method
    public void Bar() { }

    /// <summary> ... </summary>
    /// <seealso cref="?"/> //How do you reference the standard Bar() method
    void IFoo.Bar() { }
}

My guess is:

<seealso cref="IFoo.Bar()"/> //Explicitly implemented interface method
<seealso cref="Bar()"/>      //Standard method

but, I'm not sure. The ECMA guide didn't help distinguish, so I guess I'm looking for assurance that my guess is correct.

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

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

发布评论

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

评论(2

梦里兽 2024-11-14 01:41:03

使用 Sandcastle Help File Builder 进行的快速测试显示,在创建的文档中,链接 指向接口中的方法,并且 < ;seealso cref="Bar()"/> 指向类中的方法。显式实现方法的文档是从接口继承的,因此无论如何您实际上应该指向接口方法。

编辑:ReSharper 还抱怨 并将其更正为

A quick test with Sandcastle Help File Builder revealed that in the created documentation the link <seealso cref="IFoo.Bar()"/> points to the method in the interface and <seealso cref="Bar()"/> points to the method in the class. The documentation for the explicitly implemented method is inherited from the interface so you should actually point to the interface method anyway.

Edit: ReSharper also complains with <seealso cref="FooClass.IFoo.Bar()"/> and corrects it to be <seealso cref="IFoo.Bar()"/> which then points to the interface method, not the explicitly implemented one.

孤千羽 2024-11-14 01:41:03

使用 。这是 XML 文档注释文件中使用的语法。

并且不要忘记为类和接口的命名空间添加前缀。如果 FooClassIFoo 驻留在 FooNamespace 中,则必须编写 。带参数的方法需要完全限定的参数列表。

你不会因此获得 Intellisense。如果语法错误,编译器也不会抱怨。您需要使用文档生成器对此进行测试。

我用 sandcastle 测试了它,它确实有效,但它太脆弱了,无法认真使用它。

Use <seealso cref="M:FooClass.IFoo#Bar"/>. This is the syntax used in the XML document comments file.

And don't forget to prefix the namespace for both the class and the interface. If FooClass and IFoo resided in FooNamespace, you'd have to write <seealso cref="M:FooNamespace.FooClass.FooNamespace#IFoo#Bar"/>. Methods with arguments need a fully qualified parameter list.

You won't get Intellisense for this. And the compiler won't complain if you got the syntax wrong. You'll need to test this with your document generator.

I tested this with sandcastle and it works, but it's too brittle to seriously use it.

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