XML 注释——如何正确注释显式实现的接口?
代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 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.使用
。这是 XML 文档注释文件中使用的语法。并且不要忘记为类和接口的命名空间添加前缀。如果
FooClass
和IFoo
驻留在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
andIFoo
resided inFooNamespace
, 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.