StyleCop常用规则及问题.doc_第1页
StyleCop常用规则及问题.doc_第2页
StyleCop常用规则及问题.doc_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

StyleCop(Microsoft Source Analysis for C#)常用规则及问题寄菜鸟对于像我这样还是菜鸟级的程序员来说,Leader分配给我的任务,只要按时做完就OK,哪有时间去理代码的优雅,可读性!就算有,就咱这个水平,。!别人看不懂管他呢!只要我看得懂不就行了!由于平时没有注重,老大让我去维护自己以前做过的项目,结果完全傻眼了,咋一点印象都没有了呢!这不可能是我做的吧!代码混乱不堪,定义的语句只能去猜它的本意,明明只要修改一个小地方,却要从头到尾去了解整个程序,耽误时间!回想起当初写代码时为了追求能尽早的完成任务,忽略了代码的规范性,现在真是追悔莫及!所以决定从现在开始养成一个良好的编码风格,虽然编码的速度会有所降低,但是从长远出发,是很值得的!但是自己水平有限,有没有类似功能的工具呢!功夫不负有心人,它就是StyleCop.体会刚开始时,说实话感觉这个家伙有点变态,普通的一个程序,就几十个警告!而且有些不太理解!如果觉得自己这样做有充分的理由,也不必遵循StyleCop的规则。下面开始介绍StyleCop的一些我常常违反的一些规则。常用规则基础namespace names begin with an upper-case letter:.解释:命名空间的名称必须以大写字母开头Invalid spacing around the comma.解释:逗号后面需要加空格(几个无所谓)Adjacent elements must be separated by a blank line.解释:紧邻的元素之间必须用空格行隔开,例如using命名空间和namespace之间。Using directives must be sorted alphabetically by the namespaces.解释:using语句必须要按照字母排序(顺序)The code must not contain multiple blank lines in a row.解释:代码中不允许一行中有多行空行。文档规范:All using directives must be placed inside of the namespace.解释:所有using指令必需放到命名空间内。这样使用的好处:/b/abhinaba/archive/2006/08/21/709051.aspx1.Lowers the chances of namespace pollution in case the source file has more than one namespace declaration in it2.Reduces the size of the drop down in intellisense 3.Conflict detection in aliasingThe class must have a documentation header.解释:定义的类必须含有文件头标志/而且其中的内容介绍最好是带有空格的(有点变态),不然可能会报 The documentation text within the summary tag does not contain any whitespace between words, indicating that it most likely does not follow a proper grammatical structure required for documentation textThe file has no header, the header Xml is invalid, or the header is not located at the top of the file.解释:需要在文件开头上加:/-/ / Copyright MyCompany. All rights reserved./ /-类规范The class must have an access modifier.解释:类必须有访问修饰符The class must have a documentation header.解释:类必须要有文档说明,就是以“/”开头class names begin with an upper-case letter: class1.解释:类名必须以大写字母开关函数规范The method must have an access modifier.解释:方法需要访问修饰符(public private protected.)The method must have a documentation header.解释:方法必须要有文档说明,就是以“/”开头method names begin with an upper-case letter: add.解释:方法名字必须以大写字母开头字段规范:The field must have a documentation header.解释:字段必须要有文档说明,就是以“/”开头The field must have an access modifier.解释:字段必须要有修饰符Variable names must start with a lower-case letter.解释:字段的名字必须是小写开头的花括号规范Invalid spacing around the opening curly bracket.解释:左花括号前后面需要加空格Invalid spacing around the closing curly bracket.解释:右花括号前面需要加空格An opening curly bracket must not be followed by a blank line.解释:左花括号后面不能跟空行A closing curly bracket must not be preceded by a blank line.解释:右花括号前面不能有空行/规范要求标签内的内容不允许为空。内容最好是用空格隔开否则会报The documentation text within the summary tag does not contain a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论