Summary of the rules recommended by the Code lookup tool stylecop

Source: Internet
Author: User
Next article: Summary and translation of SytleCop rules in code lookup tools. This article is mainly a suggested Rule point summarized from my personal point of view.
Recommended Rule points

1. standard XML comments must be added to common interfaces, classes, methods, attributes, and fields (this problem can be solved through code analysis provided by)

2. SA1516: CSharp. Layout: Adjacent elements must be separated by a blank line

Generally, there must be a blank line between adjacent elements.

3. SA1603: The DocumentationMustContainValidXml comment must be legal (the keyword in the comment cannot be incorrect)

4. SA1604: ElementDocumentationMustHaveSummary element annotation must contain the Summary keyword

5. SA1606: text must be added to the ElementDocumentationMustHaveSummaryText Summary node.

6. SA1608: ElementDocumentationMustNotHaveDefaultSummary Summary annotation cannot use the annotation text that comes with the Compiler

7. SA1609: the comments of the PropertyDocumentationMustHaveValue attribute must contain the <Value> node.

8. SA1610: Comment on the PropertyDocumentationMustHaveValueText attribute <Value> the node must contain text values.

9. sa1611: The elementparametersmustbeincluented parameter must be commented out.

10. sa1612: the number of elementparameterdocumentationmustmatchelementparameters parameters must be the same as the number in the comment.

11. sa1613: The parameter name must be included in the comments of elementparameterdocumentationmustdeclareparametername.

12. sa1614: The parameter comment node of elementparameterdocumentationmusthavetext cannot be empty.

13. sa1615: the return value of elementreturnvaluemustbeincluented must be annotated.

14. sa1616: elementreturnvaluedocumentationmusthavetext

15. sa1617: voidreturnvaluemustnotbeincluented null. the return value must not be annotated.

16. sa1623: the comments of the propertysummarydocumentationmustmatchaccessors attribute must match the read and write permissions of the attribute. Private attributes cannot appear in the comment.

17. sa1624: the protected keyword must be ignored in the annotation of the propertysummarydocumentationmustomitsetaccessorwithrestrictedaccess attribute. If the parameter is public

18. SA1625: the annotations of ElementDocumentationMustNotBeCopiedAndPasted parameters cannot be identical (to avoid copy and post operations)

19. SA1631: The DocumentationMustMeetCharacterPercentage comment node cannot contain too many characters (for example, '---------------------------------------------' is not allowed)

20. SA1642: ConstructorSummaryDocumentationMustBeginWithStandardText constructor annotation standard: "Initializes a new instance of the <see cref =" Customer {T} "/> class ."

21. SA1644: blank lines cannot appear in the documentationheadersmustnotcontainblklines comment

22. SA1500: CurlyBracketsForMultiLineStatementsMustNotShareLine.

Standard Format: public StRsvrRFun ()



23. SA1501: The StatementMustNotBeOnASingleLine statement cannot share a row.

24. SA1502: The ElementMustNotBeOnASingleLine statement cannot share a row.

25. SA1503: CurlyBracketsMustNotBeOmitted cannot be omitted even in the case of a single line of code.

26. SA1504: The read/write attributes of AllAccessorsMustBeSingleLineOrMultiLine are either written in multiple lines in the same industry, and the rules are not uniform (I suggest writing in multiple lines ).

27. SA1505: no blank lines can be left behind the curly arc starting with openingcurlybracketsmustnotbefollowedbyblkline.

28. SA1506: elementdocumentationheadersmustnotbefollowedbyblkline cannot have blank lines between the comment header and the element

29. SA1507: codemustnotcontainmultipleblklinesinarow does not allow multiple blank rows to be placed next to each other (I suggest writing a blank row)

30. SA1508: The curly arc at the end of closingcurlybracketsmustnotbeprecededbyblkline cannot be left blank.

31. SA1509: The curly arc starting with openingcurlybracketsmustnotbeprecededbyblkline cannot start with a blank line.

32. SA1510: no blank lines are allowed between statements connected to chainedstatementblocksmustnotbeprecededbyblkline. For example, no blank lines are allowed between try and catch statements.

33. SA1511: whiledofootermustnotbeprecededbyblkline is the same as SA1510. There cannot be blank lines between Do and While statements.

34. SA1512: singlelinecommentsmustnotbefollowedbyblkline single line comment cannot be followed by blank lines

35. SA1513: there must be a blank line after closingcurlybracketmustbefollowedbyblkline ends the arc.

36. SA1514: there must be a blank line before ElementDocumentationHeaderMustBePrecededByBlankLine header Annotation

37. SA1515

38. SA1516: there must be a blank line between elements adjacent to ElementsMustBeSeparatedByBlankLine.

39. SA1517: no blank lines can appear before the characters in the header of the codemustnotcontainblklinesatstartoffile code file.

40. SA1518: no blank lines can appear after the characters at the end of the codemustnotcontainblklinesatendoffile code file

41. SA1407: The ArithmeticExpressionsMustDeclarePrecedence arithmetic expression must explicitly indicate its priority (this is in conflict with SA1119)

42. SA1408: The ConditionalExpressionsMustDeclarePrecedence condition expression must explicitly indicate its priority (this clause conflicts with SA1119). For example, "if (x | (y & z & a) | B)"

43. SA1409: RemoveUnnecessaryCode Remove useless code

44. SA1410: RemoveDelegateParenthesisWhenPossible calls a c # anonymous method that does not contain any method parameters and must contain an empty bracket. (I do not recommend using the anonymous method or anonymous delegate syntax, follow-up sharing for specific reasons)

45. SA1302: The InterfaceNamesMustBeginWithI interface must start with an "I" letter.

SA1208: systemusingdirevesmustbeplacedbeforeotherusingdireves ves system-level references before other references (formatted code will automatically orchestrate the using part according to this rule)

46. SA1209: usingaliasdirectivesmustbeplacedafterotherusingdireves ves using

47. SA1210: usingdirevesmustbeorderedalphabeticallybynamespace using in alphabetical order

48. SA1211: UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName

49. SA1212: PropertyAccessorsMustFollowOrder attributes are obtained in

50, SA1213: EventAccessorsMustFollowOrder time first remove in add

51. SA1100: DoNotPrefixCallsWithBaseUnlessLocalImplementationExists

Change the 'base. 'prefix to 'this .'.

52. SA1101: PrefixLocalCallsWithThis 'this. 'prefix cannot be omitted

53. SA1102: QueryClauseMustFollowPreviousClause: either the same row or the keywords are distributed across multiple rows. The keywords are left aligned.

54. SA1106: CodeMustNotContainEmptyStatements blank declarations are not allowed.

55. SA1107: CodeMustNotContainMultipleStatementsOnOneLine multiple statement statements cannot appear in the same row

56. SA1108: Illegal Use Case of BlockStatementsMustNotContainEmbeddedComments:

If (x! = Y)

// Make sure x does not equal y



57. sa1109: blockstatementsmustnotcontainembeddedregions illegal use case:

If (X! = Y)

# Region



# Endregion

58. sa1110: the arc starting from the openingparenthesismustbeondeclarationline method must be on the declared line.

59. sa1111: closingparenthesismustbeonlineoflastparameter

60. sa1112: closingparenthesismustbeonlineofopeningparenthesis

61. sa1113: commamustbeonsamelineaspreviousparameter must be the same as the previous parameter.

62. sa1114: parameterlistmustfollowdeclaration

Make sure that the parameter list is in the same line as the start bracket, or the parameter of the other line must be in the same line

63. sa1115: The parametermustfollowcomma parameter and the parameter cannot be separated by blank lines.

64. sa1116: splitparametersmuststartonlineafterdeclaration all parameters in the same line or the following example:

Public String joinname (

String first,

String last)

65. sa1117: parametersmustbeonsamelineorseparatelines same as above

66. sa1121: usebuiltintypealias uses an embedded type alias, for example:

Type alias


Fully qualified type



System. Boolean



System. byte



System. Char



System. Decimal



System. Double



System. int16



System. int32



System. int64



System. Object



System. sbyte



System. Single



System. String



System. uint16



System. uint32



System. uint64

67. sa1122: usestringemptyforemptystrings

Sample Code: "string S = string. Empty;" cannot be written as "string S = "";"

We recommend that you disable the Rule points.

1. sa1650: CSHARP. Documentation: The documentation text within the summary tag contains incorrectly spelled words: the exception test is not good enough to support Chinese characters. The spelling check is not recognized.

2. sa1200: CSHARP. Ordering: All using ctictives must be placed inside of the namespace

Generally, the using statement should be placed inside the namespace, so it is not necessary to take this item. You can simply use the default position of.

3. Other blocking items are listed in different columns.

In actual work (manually triggered, then I will use cc. Net for script calls ):

The stylecop settings for each project are recorded in a file named "Settings. stylecop". replace other projects with the settings configured by copy. Operation

Now I will share my local rule file with you: Download the full set of stylecop documents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.