当然,这需要更多的纪律,因为它更难写。它也不太有用,因为你不会在源代码中看到它们。但是,如果您想使用 XML 注释来构建文档,那么这可能是一个好方法。
You can define the comment in a separate file and then use the <include> tag (see MSDN). This way, you can write the comment just once, but include it as a documentation in multiple different places (e.g. the declaration and the implementation of an interface).
Of course, this requires a bit more discipline, because it is more difficult to write. It is also a bit less useful, because you won't see them in the source code. However, if you want to use XML comments to build documentation, then it is probably a good approach.
Prefer to comment both. Remember that the interface method definition should contain all of the information the consumer requires to either implement or call it. The implementation is relevant to consumers as well as far as choosing which one to use, so it should be appropriate to comment as well.
The bottom line is to err on the side of more clarity rather than less.
If you implementation is more general or more specific e.g. can work with wider inputs or returns or throws more specific outputs, then document that on the implementation.
If the implementation does not differ from the interface, then you can use <inheritdoc />.
发布评论
评论(3)
您可以在单独的文件中定义注释,然后使用
标记 (参见 MSDN)。这样,您只需编写一次注释,即可将其作为文档包含在多个不同的位置(例如接口的声明和实现)。当然,这需要更多的纪律,因为它更难写。它也不太有用,因为你不会在源代码中看到它们。但是,如果您想使用 XML 注释来构建文档,那么这可能是一个好方法。
You can define the comment in a separate file and then use the
<include>
tag (see MSDN). This way, you can write the comment just once, but include it as a documentation in multiple different places (e.g. the declaration and the implementation of an interface).Of course, this requires a bit more discipline, because it is more difficult to write. It is also a bit less useful, because you won't see them in the source code. However, if you want to use XML comments to build documentation, then it is probably a good approach.
更愿意同时发表评论。请记住,接口方法定义应包含消费者实现或调用它所需的所有信息。该实施与消费者以及选择使用哪一个相关,因此也应该适当地发表评论。
最重要的是,宁可更加清晰,也不要过于清晰。
Prefer to comment both. Remember that the interface method definition should contain all of the information the consumer requires to either implement or call it. The implementation is relevant to consumers as well as far as choosing which one to use, so it should be appropriate to comment as well.
The bottom line is to err on the side of more clarity rather than less.
记录您的接口。
如果您的实现更通用或更具体,例如可以使用更广泛的输入或返回或抛出更具体的输出,则在实现中记录该内容。
如果实现与接口没有区别,那么您可以使用
。相关:继承 C# 中的文档?
Document you interfaces.
If you implementation is more general or more specific e.g. can work with wider inputs or returns or throws more specific outputs, then document that on the implementation.
If the implementation does not differ from the interface, then you can use
<inheritdoc />
.Related: Inherit documentation in C#?