【问题标题】:XML Comments -- How do you comment explicitly implemented interfaces properly?XML 注释——您如何正确地注释显式实现的接口?
【发布时间】:2011-08-25 11:54:37
【问题描述】:

代码:

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 指南没有帮助区分,所以我想我正在寻找我的猜测是正确的保证。

【问题讨论】:

    标签: c# xml-comments explicit-interface explicit-implementation


    【解决方案1】:

    使用&lt;seealso cref="M:FooClass.IFoo#Bar"/&gt;。这是 XML 文档 cmets 文件中使用的语法。

    并且不要忘记为类和接口的命名空间添加前缀。如果FooClassIFoo 驻留在FooNamespace 中,则必须写为&lt;seealso cref="M:FooNamespace.FooClass.FooNamespace#IFoo#Bar"/&gt;。带参数的方法需要一个完全限定的参数列表。

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

    我用沙堡测试了这个,它可以工作,但它太脆,不能认真使用。

    【讨论】:

      【解决方案2】:

      使用 Sandcastle Help File Builder 进行的快速测试显示,在创建的文档中,链接 &lt;seealso cref="IFoo.Bar()"/&gt; 指向接口中的方法,&lt;seealso cref="Bar()"/&gt; 指向类中的方法。显式实现方法的文档是从接口继承的,所以无论如何你都应该指向接口方法。

      编辑:ReSharper 还抱怨 &lt;seealso cref="FooClass.IFoo.Bar()"/&gt; 并将其更正为 &lt;seealso cref="IFoo.Bar()"/&gt; 然后指向接口方法,而不是显式实现的方法。

      【讨论】:

      • 这就是我的想法,但我不是 100% 确定。感谢您澄清这一点。
      • 那么有没有办法通过xml cmets来引用显式定义的接口方法呢?
      猜你喜欢
      • 1970-01-01
      • 2018-07-19
      • 2021-10-16
      • 2010-09-13
      • 2017-01-24
      • 2018-03-11
      • 1970-01-01
      • 2010-10-19
      • 2011-08-29
      相关资源
      最近更新 更多