.NET 接口上正确的 xml 注释

发布于 2024-09-15 08:12:36 字数 195 浏览 4 评论 0原文

如果有一个接口和一个实现它的类,并且您希望在 VS 智能感知或文档中使用它的 xml 注释,您会将 xml 注释放在哪里?在接口的方法上还是在具体的类方法上?正确的方法是什么?

我的想法是将它放在接口中,因为我们使用接口声明变量。而且我认为如果我也对具体类发表评论并看到这可能会导致同一方法出现不同的文档,那么这是多余的。

有什么想法、建议吗?

if there is an interface and a class that implements it and you want to have the the xml comment on it to be used in VS intellisense or documentation where would you put the xml comment? on the interface's methods or on the concrete class methods? What is the correct way?

My thoughts are to put it in the interface because we are declaring the variables using interface. And i think its redundant if i also put a comment on the concrete class and see this may lead to different documentation on same method.

Any ideas, advice?

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

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

发布评论

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

评论(1

云淡月浅 2024-09-22 08:12:36

您应该记录任何公共成员。如果您已将 ISomeInterface.SomeMember 实现为 public void SomeMember 那么应该对其进行记录。一方面,读者会将其视为类的一部分,并且只有通过阅读文档(如果不存在,他们就无法知道要查看文档),他们才会知道它是在该接口中定义的。如果它被实现为 void ISomeInterface.SomeMember ,那么它就不那么重要了,因为它不会被视为类的公共接口的一部分。

有时了解有关特定类如何实现给定接口成员的详细信息也很重要。

另一方面,给出非常简短的描述并引导人们查看接口的文档以获取更多信息可能是合理的。

You should document on any public member. If you've implemented ISomeInterface.SomeMember as public void SomeMember then it should be documented. For one thing the reader will see this as part of your class, and only by reading documentation (which they can't know to look at if it isn't there) will they know it's defined in that interface. If it's implemented as void ISomeInterface.SomeMember then it's less important, as it won't be seen as part of the public interface of the class.

It's also sometimes important to know details about how your particular class has implemented a given interface member.

On the other hand, it may be reasonable to give a very short description and direct people to the interface's documentation for more.

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