简体   繁体   English

使用C#Intellisense注释的最佳实践

[英]Best Practices on using C# Intellisense Comments

We have a Visual Studio 2010 solution that contains several C# projects in accordance with Jeffery Palermo's Onion Architecture pattern ( http://jeffreypalermo.com/blog/the-onion-architecture-part-1/ ). 我们有一个Visual Studio 2010解决方案,它包含几个符合Jeffery Palermo的Onion Architecture模式的C#项目( http://jeffreypalermo.com/blog/the-onion-architecture-part-1/ )。 We want to add the Visual Studio Intellisense Comments using the triple slashes, but we want to see if anyone knows of best practices on how far to take this. 我们想使用三条斜线添加Visual Studio Intellisense评论,但我们希望看看是否有人知道有多远的最佳实践。 Do we start all the way down in the Model in the Core project, and work up through Infrastructure and into the DataAccess Services and Repositories, and into the User Interface? 我们是否在Core项目中的模型中一直向下开始,并通过基础架构,DataAccess服务和存储库以及用户界面进行操作? Or is it better to use these comments in a more limited fashion, and if so what are the important objects to apply the Intellisense Comments to? 或者以更有限的方式使用这些评论更好,如果是这样,那么应用Intellisense评论的重要对象是什么?

Add them to any methods exposed in public APIs, that way you can give the caller all the information they need when working with a foreign interface. 将它们添加到公共API中公开的任何方法,这样您就可以为调用者提供使用外部接口时所需的所有信息。 For example, which exceptions the method may throw and other remarks. 例如,该方法可能抛出哪些异常和其他评论。

It's still beneficial to add these kinds of comments to private methods, I do it anyway to be consistent. 将这些类型的注释添加到私有方法仍然是有益的,我仍然这样做是为了保持一致。 It also helps if you plan on generating documentation from the comments. 如果您计划从评论中生成文档,这也会有所帮助。

While, technically, there is such a thing as too much documentation, 99.99999% of the time this exception doesn't apply. 虽然从技术上讲,存在太多文档,但99.99999%的时间不适用此例外。

Document everything as much as you can. 尽可能多地记录所有内容。 Formal, informal, stream of thought..every scrap of comments will help some poor soul who inherits your code or has to interface with it. 正式的,非正式的,思想流。每一条评论都会帮助一些继承你的代码或者必须与之交互的穷人。

(It's like the old rule "The error may be in the Compiler and not your code. Compilers have errors too. This is not one of those times.") (这就像旧规则“错误可能在编译器而不是你的代码。编译器也有错误。这不是那个时代之一。”)

Do we start all the way down in the Model in the Core project, and work up through Infrastructure and into the DataAccess Services and Repositories, and into the User Interface? 我们是否在Core项目中的模型中一直向下开始,并通过基础架构,DataAccess服务和存储库以及用户界面进行操作? Yes

Or is it better to use these comments in a more limited fashion, and if so what are the important objects to apply the Intellisense Comments to? 或者以更有限的方式使用这些评论更好,如果是这样,那么应用Intellisense评论的重要对象是什么? If you want to. 如果你想。 Apply them to any function you write, and not what VS autogenerates 将它们应用于您编写的任何函数,而不是VS自动生成的函数

I've seen limited "intellisense" comments..but extensive in-code comments that follow. 我已经看到有限的“智能感知”评论......但随后是广泛的代码内评论。 So long as the "content" is there, life will be good. 只要“内容”存在,生活就会好。 I generally include a brief blurb about each function in the intellisense comments, but put the majority of "here's why i did this" in the function and dead-tree documents. 我通常在intellisense评论中包含关于每个函数的简短模糊,但是在函数和死树文档中放置了“这就是我为什么这样做”的大部分内容。

I agree with fletcher. 我同意弗莱彻的观点。 Start with public facing classes and methods and then work your way down into private code. 从面向公众的类和方法开始,然后逐步进入私有代码。 If you were starting from scratch I would highly recommend adding the XML comments to all code for your own convenience, but in this case starting with public methods and then updating other classes whenever you go in to update them is a good solution. 如果您从头开始,我强烈建议您为自己的方便将XML注释添加到所有代码中,但在这种情况下,从公共方法开始,然后在进行更新时更新其他类是一个很好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM