The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-)...
Transcript of The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-)...
![Page 1: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/1.jpg)
TheStyleCoptoolprovideswarningsthatindicatestyleandconsistencyruleviolationsinC#code.Bydefault,thetoolintegratesintoVisualStudio2008andVisualStudio2010,anditcanalsobeintegratedintoMSBuild-basedbuildsystems.Itisalsopossibletoauthorcustomrulestorunwithinthetool,andtocreateawrapperhosttointegratethetoolintoacustombuildenvironment.
StyleCopRulesDocumentation
StartingwithStyleCop4.3.2,itispossibletosuppressthereportingofruleviolationsbyaddingsuppressionattributeswithinthesourcecode.
RuleSuppressions
![Page 2: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/2.jpg)
TheStyleCoptoolprovideswarningsthatindicatestyleandconsistencyruleviolationsinC#code.Thewarningsareorganizedintoruleareassuchasdocumentation,layout,naming,ordering,readability,spacing,andsoforth.Eachwarningsignifiesaviolationofastyleorconsistencyrule.ThissectionprovidesanexplanationofeachofthedefaultStyleCoprules.
![Page 3: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/3.jpg)
InThisSectionDocumentationRules(SA1600-)
Ruleswhichverifythecontentandformattingofcodedocumentation.
LayoutRules(SA1500-)
Ruleswhichenforcecodelayoutandlinespacing.
MaintainabilityRules(SA1400-)
Ruleswhichimprovecodemaintainability.
NamingRules(SA1300-)
Ruleswhichenforcenamingrequirementsformembers,types,andvariables.
OrderingRules(SA1200-)
Ruleswhichenforceastandardorderingschemeforcodecontents.
ReadabilityRules(SA1100-)
Ruleswhichensurethatthecodeiswell-formattedandreadable.
SpacingRules(SA1000-)
Ruleswhichenforcespacingrequirementsaroundkeywordsandsymbolsinthecode.
![Page 4: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/4.jpg)
RelatedTopicsStartingwithStyleCop4.3.2,itispossibletosuppressthereportingofruleviolationsbyaddingsuppressionattributeswithinthesourcecode.
RuleSuppressions
![Page 5: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/5.jpg)
Ruleswhichverifythecontentandformattingofcodedocumentation.
SA1600:ElementsMustBeDocumented
SA1601:PartialElementsMustBeDocumented
SA1602:EnumerationItemsMustBeDocumented
SA1603:DocumentationMustContainValidXml
SA1604:ElementDocumentationMustHaveSummary
SA1605:PartialElementDocumentationMustHaveSummary
SA1606:ElementDocumentationMustHaveSummaryText
SA1607:PartialElementDocumentationMustHaveSummaryText
SA1608:ElementDocumentationMustNotHaveDefaultSummary
SA1609:PropertyDocumentationMustHaveValue
SA1610:PropertyDocumentationMustHaveValueText
SA1611:ElementParametersMustBeDocumented
SA1612:ElementParameterDocumentationMustMatchElementParameters
SA1613:ElementParameterDocumentationMustDeclareParameterName
SA1614:ElementParameterDocumentationMustHaveText
SA1615:ElementReturnValueMustBeDocumented
SA1616:ElementReturnValueDocumentationMustHaveValue
SA1617:VoidReturnValueMustNotBeDocumented
SA1618:GenericTypeParametersMustBeDocumented
SA1619:GenericTypeParametersMustBeDocumentedPartialClass
SA1620:GenericTypeParameterDocumentationMustMatchTypeParameters
SA1621:GenericTypeParameterDocumentationMustDeclareParameterName
SA1622:GenericTypeParameterDocumentationMustHaveText
SA1623:PropertySummaryDocumentationMustMatchAccessors
SA1624:
![Page 6: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/6.jpg)
PropertySummaryDocumentationMustOmitSetAccessorWithRestricedAccess
SA1625:ElementDocumentationMustNotBeCopiedAndPasted
SA1626:SingleLineCommentsMustNotUseDocumentationStyleSlashes
SA1627:DocumentationTextMustNotBeEmpty
SA1628:DocumentationTextMustBeginWithACapitalLetter
SA1629:DocumentationTextMustEndWithAPeriod
SA1630:DocumentationTextMustContainWhitespace
SA1631:DocumentationTextMustMeetCharacterPercentage
SA1632:DocumentationTextMustMeetMinimumCharacterLength
SA1633:FileMustHaveHeader
SA1634:FileHeaderMustShowCopyright
SA1635:FileHeaderMustHaveCopyrightText
SA1636:FileHeaderCopyrightTextMustMatch
SA1637:FileHeaderMustContainFileName
SA1638:FileHeaderFileNameDocumentationMustMatchFileName
SA1639:FileHeaderMustHaveSummary
SA1640:FileHeaderMustHaveValidCompanyText
SA1641:FileHeaderCompanyNameTextMustMatch
SA1642:ConstructorSummaryDocumentationMustBeginWithStandardText
SA1643:DestructorSummaryDocumentationMustBeginWithStandardText
SA1644:DocumentationHeadersMustNotContainBlankLines
SA1645:IncludedDocumentationFileDoesNotExist
SA1646:IncludedDocumentationXPathDoesNotExist
SA1647:IncludeNodeDoesNotContainValidFileAndPath
SA1648:InheritDocMustBeUsedWithInheritingClass
SA1649:FileHeaderFileNameDocumentationMustMatchTypeName
![Page 7: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/7.jpg)
TypeName ElementsMustBeDocumented
CheckId SA1600
Category DocumentationRules
![Page 8: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/8.jpg)
CauseAC#codeelementismissingadocumentationheader.
![Page 9: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/9.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifanelementiscompletelymissingadocumentationheader,oriftheheaderisempty.InC#thefollowingtypesofelementscanhavedocumentationheaders:classes,constructors,delegates,enums,events,finalizers,indexers,interfaces,methods,properties,andstructs.
![Page 10: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/10.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorfill-inadocumentationheaderfortheelement.
thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 11: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/11.jpg)
TypeName PartialElementsMustBeDocumented
CheckId SA1601
Category DocumentationRules
![Page 12: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/12.jpg)
CauseAC#partialelementismissingadocumentationheader.
![Page 13: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/13.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifapartialelement(anelementwiththepartialattribute)iscompletelymissingadocumentationheader,oriftheheaderisempty.InC#thefollowingtypesofelementscanbeattributedwiththepartialattribute:classes,methods.
Whendocumentationisprovidedonmorethanonepartofthepartialclass,thedocumentationforthetwoclassesmaybemergedtogethertoformasinglesourceofdocumentation.Forexample,considerthefollowingtwopartsofapartialclass:
///<summary>
///DocumentationforthefirstpartofClass1.
///</summary>
publicpartialclassClass1
{
}
///<summary>
///DocumentationforthesecondpartofClass1.
///</summary>
publicpartialclassClass1
![Page 14: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/14.jpg)
{
}
Thesetwodifferentpartsofthesamepartialclasseachprovidedifferentdocumentationfortheclass.WhenthedocumentationforthisclassisbuiltintoanSDK,thetoolbuildingthedocumentationwilleitherchoosetouseonlyonepartofthedocumentationfortheclassandignoretheotherparts,or,insomecases,itmaymergethetwosourcesofdocumentationtogether,toformastringlike:“DocumentationforthefirstpartofClass1.DocumentationforthesecondpartofClass1.”
Forthesereasons,itcanbeproblematictoprovideSDKdocumentationonmorethanonepartofthepartialclass.However,itisstilladvisabletodocumenteachpartoftheclass,toincreasethereadabilityandmaintainabilityofthecode,andStyleCopwillrequirethateachpartoftheclasscontainheaderdocumentation.
Thisproblemissolvedthroughtheuseofthe<content>tag,whichcanreplacethe<summary>tagforpartialclasses.TherecommendedpracticefordocumentingpartialclassesistoprovidetheofficialSDKdocumentationfortheclassonthemainpartofthepartialclass.Thisdocumentationshouldbewrittenusingthestandard<summary>tag.Allotherpartsofthepartialclassshouldomitthe<summary>tagcompletely,andreplaceitwitha<content>tag.ThisallowsthedevelopertodocumentallpartsofthepartialclasswhilestillcentralizingalloftheofficialSDKdocumentationfortheclassontoonepartoftheclass.The<content>tagswillbeignoredbytheSDKdocumentationtools.
![Page 15: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/15.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorfill-inadocumentationheaderfortheelement.
Forexample,thefollowingexampleshowstwopartsofapartialclass,onecontaininga<summary>headerandanothercontaininga<content>header.
///<summary>
///Representsacustomerinthedatabase.
///</summary>
publicpartialclassCustomer
{
}
///<content>
///Containsauto-generatedfunctionalityfortheCustomerclass.
///</content>
publicpartialclassCustomer
{
}
![Page 16: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/16.jpg)
TypeName EnumerationItemsMustBeDocumented
CheckId SA1602
Category DocumentationRules
![Page 17: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/17.jpg)
CauseAnitemwithinaC#enumerationismissinganXmldocumentationheader.
![Page 18: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/18.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenanitemwithinanenumerationismissingaheader.Forexample:
///<summary>
///Typesofanimals.
///</summary>
publicenumAnimals
{
Dog,
Cat,
Horse
}
![Page 19: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/19.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addadocumentationheaderforeachitemwithintheenum.Forexample:
///<summary>
///Typesofanimals.
///</summary>
publicenumAnimals
{
///<summary>
///Representsadog.
///</summary>
Dog,
///<summary>
///Representsacat.
///</summary>
Cat,
///<summary>
///Representsahorse.
![Page 20: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/20.jpg)
///</summary>
Horse
}
![Page 21: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/21.jpg)
TypeName DocumentationMustContainValidXml
CheckId SA1603
Category DocumentationRules
![Page 22: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/22.jpg)
CauseTheXmlwithinaC#element’sdocumentheaderisbadlyformed.
![Page 23: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/23.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
AviolationofthisruleoccurswhenthedocumentationXmlisbadlyformedandcannotbeparsed.ThiscanoccuriftheXmlcontainsinvalidcharacters,orifanXmlnodeismissingaclosingtag,forexample.
![Page 24: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/24.jpg)
HowtoFixViolationsTofixaviolationofthisrule,replacethebadlyformedXmlwithvalidXmlthatcanbeparsedbyastandardXmlparser.
ThefollowingexampleshowsaclasscontaininginvalidXmlwithinitsdocumentationheader.Theclosingtagforthe<summary>nodeisinvalid.
///<summary>
///AnexampleofbadlyformedXml.
///</summa3ry>
publicclassExample
{
}
![Page 25: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/25.jpg)
TypeName ElementDocumentationMustHaveSummary
CheckId SA1604
Category DocumentationRules
![Page 26: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/26.jpg)
CauseTheXmlheaderdocumentationforaC#elementismissinga<summary>tag.
![Page 27: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/27.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhentheelementdocumentationismissinga<summary>tag.
![Page 28: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/28.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addandfill-ina<summary>tagfortheelement,containingadescriptionoftheelement.
ThefollowingexampleshowsaclasscontaininginvalidXmlwithinitsdocumentationheader.Theclosingtagforthe<summary>nodeisinvalid.
///<summary>
///Representsacustomerinthedatabase.
///</summary>
publicclassCustomer
{
}
![Page 29: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/29.jpg)
TypeName PartialElementDocumentationMustHaveSummary
CheckId SA1605
Category DocumentationRules
![Page 30: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/30.jpg)
CauseThe<summary>or<content>tagwithinthedocumentationheaderforaC#codeelementismissingorempty.
![Page 31: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/31.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenthedocumentationheaderforapartialelement(anelementwiththepartialattribute)ismissinga<summary>or<content>tag,orcontainsanempty<summary>or<content>tagwhichdoesnotcontainadescriptionoftheelement.InC#thefollowingtypesofelementscanbeattributedwiththepartialattribute:classes,methods.
Whendocumentationisprovidedonmorethanonepartofthepartialclass,thedocumentationforthetwoclassesmaybemergedtogethertoformasinglesourceofdocumentation.Forexample,considerthefollowingtwopartsofapartialclass:
///<summary>
///DocumentationforthefirstpartofClass1.
///</summary>
publicpartialclassClass1
{
}
///<summary>
///DocumentationforthesecondpartofClass1.
///</summary>
publicpartialclassClass1
![Page 32: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/32.jpg)
{
}
Thesetwodifferentpartsofthesamepartialclasseachprovidedifferentdocumentationfortheclass.WhenthedocumentationforthisclassisbuiltintoanSDK,thetoolbuildingthedocumentationwilleitherchoosetouseonlyonepartofthedocumentationfortheclassandignoretheotherparts,or,insomecases,itmaymergethetwosourcesofdocumentationtogether,toformastringlike:“DocumentationforthefirstpartofClass1.DocumentationforthesecondpartofClass1.”
Forthesereasons,itcanbeproblematictoprovideSDKdocumentationonmorethanonepartofthepartialclass.However,itisstilladvisabletodocumenteachpartoftheclass,toincreasethereadabilityandmaintainabilityofthecode,andStyleCopwillrequirethateachpartoftheclasscontainheaderdocumentation.
Thisproblemissolvedthroughtheuseofthe<content>tag,whichcanreplacethe<summary>tagforpartialclasses.TherecommendedpracticefordocumentingpartialclassesistoprovidetheofficialSDKdocumentationfortheclassonthemainpartofthepartialclass.Thisdocumentationshouldbewrittenusingthestandard<summary>tag.Allotherpartsofthepartialclassshouldomitthe<summary>tagcompletely,andreplaceitwitha<content>tag.ThisallowsthedevelopertodocumentallpartsofthepartialclasswhilestillcentralizingalloftheofficialSDKdocumentationfortheclassontoonepartoftheclass.The<content>tagswillbeignoredbytheSDKdocumentationtools.
![Page 33: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/33.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addandfill-ina<summary>or<content>tagwithadescriptionofthecodeelement.
Thefollowingexampleshowsapartialclasswithafill-in<summary>tag.
///<summary>
///Representsacustomerinthedatabase.
///</summary>
publicpartialclassCustomer
{
}
![Page 34: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/34.jpg)
TypeName ElementDocumentationMustHaveSummaryText
CheckId SA1606
Category DocumentationRules
![Page 35: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/35.jpg)
CauseThe<summary>tagwithinthedocumentationheaderforaC#codeelementisempty.
![Page 36: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/36.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenthedocumentationheaderforanelementcontainsanempty<summary>tagwhichdoesnotcontainadescriptionoftheelement.
![Page 37: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/37.jpg)
HowtoFixViolationsTofixaviolationofthisrule,fill-inthe<summary>tagwithadescriptionofthecodeelement.
Example:
Thefollowingexampleshowsamethodwhichcontainsanempty<summary>tag.
///<summary></summary>
///<paramname="customerId">TheIDofthecustomertofind.</param>
///<returns>Thecustomer,ornullifthecustomercouldnotbe
///found.</returns>
publicCustomerFindCustomer(intcustomerId)
{
//...findsthecustomer...
}
![Page 38: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/38.jpg)
TypeName PartialElementDocumentationMustHaveSummaryText
CheckId SA1607
Category DocumentationRules
![Page 39: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/39.jpg)
CauseThe<summary>or<content>tagwithinthedocumentationheaderforaC#codeelementisempty.
![Page 40: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/40.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenthedocumentationheaderforapartialelement(anelementwiththepartialattribute)containsanempty<summary>tagor<content>tagwhichdoesnotcontainadescriptionoftheelement.InC#thefollowingtypesofelementscanbeattributedwiththepartialattribute:classes,methods.
Whendocumentationisprovidedonmorethanonepartofthepartialclass,thedocumentationforthetwoclassesmaybemergedtogethertoformasinglesourceofdocumentation.Forexample,considerthefollowingtwopartsofapartialclass:
///<summary>
///DocumentationforthefirstpartofClass1.
///</summary>
publicpartialclassClass1
{
}
///<summary>
///DocumentationforthesecondpartofClass1.
///</summary>
publicpartialclassClass1
![Page 41: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/41.jpg)
{
}
Thesetwodifferentpartsofthesamepartialclasseachprovidedifferentdocumentationfortheclass.WhenthedocumentationforthisclassisbuiltintoanSDK,thetoolbuildingthedocumentationwilleitherchoosetouseonlyonepartofthedocumentationfortheclassandignoretheotherparts,or,insomecases,itmaymergethetwosourcesofdocumentationtogether,toformastringlike:“DocumentationforthefirstpartofClass1.DocumentationforthesecondpartofClass1.”
Forthesereasons,itcanbeproblematictoprovideSDKdocumentationonmorethanonepartofthepartialclass.However,itisstilladvisabletodocumenteachpartoftheclass,toincreasethereadabilityandmaintainabilityofthecode,andStyleCopwillrequirethateachpartoftheclasscontainheaderdocumentation.
Thisproblemissolvedthroughtheuseofthe<content>tag,whichcanreplacethe<summary>tagforpartialclasses.TherecommendedpracticefordocumentingpartialclassesistoprovidetheofficialSDKdocumentationfortheclassonthemainpartofthepartialclass.Thisdocumentationshouldbewrittenusingthestandard<summary>tag.Allotherpartsofthepartialclassshouldomitthe<summary>tagcompletely,andreplaceitwitha<content>tag.ThisallowsthedevelopertodocumentallpartsofthepartialclasswhilestillcentralizingalloftheofficialSDKdocumentationfortheclassontoonepartoftheclass.The<content>tagswillbeignoredbytheSDKdocumentationtools.
![Page 42: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/42.jpg)
HowtoFixViolationsTofixaviolationofthisrule,fill-inthecontentsofthesummarytagorcontenttagwithadescriptionofthecodeelement.
Thefollowingexampleshowsamethodwhichcontainsanempty<summary>tag.
///<summary></summary>
///<paramname="customerId">TheIDofthecustomertofind.</param>
///<returns>Thecustomer,ornullifthecustomercouldnotbefound.</returns>
publicCustomerFindCustomer(intcustomerId)
{
//...findsthecustomer...
}
Tofixtheviolation,addvalidsummarytext.Forexample:
///<summary>AttemptstolocatearecordforthecustomerwiththegivenID.</summary>
///<paramname="customerId">TheIDofthecustomertofind.</param>
///<returns>Thecustomer,ornullifthecustomercouldnotbefound.</returns>
publicCustomerFindCustomer(intcustomerId)
{
![Page 43: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/43.jpg)
//...findsthecustomer...
}
![Page 44: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/44.jpg)
TypeName ElementDocumentationMustNotHaveDefaultSummary
CheckId SA1608
Category DocumentationRules
![Page 45: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/45.jpg)
CauseThe<summary>tagwithinanelement’sXmlheaderdocumentationcontainsthedefaulttextgeneratedbyVisualStudioduringthecreationoftheelement.
![Page 46: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/46.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
VisualStudioprovideshelperfunctionalityforaddingnewelementssuchasclassestoaproject.VisualStudiowillcreateadefaultdocumentationheaderforthenewclassandfillinthisheaderwithdefaultdocumentationtext.
Aviolationofthisruleoccurswhenthe<summary>tagforacodeelementstillcontainsthedefaultdocumentationtextgeneratedbyVisualStudio.
![Page 47: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/47.jpg)
HowtoFixViolationsTofixaviolationofthisrule,replacethedefaultdocumentationtextwithnewtextdescribingthecontentsofthecodeelement.
ThefollowingexampleshowsaclasswhichcontainsthedefaultsummarytextgeneratedbyVisualStudio.
///<summary>
///SummarydescriptionfortheExampleclass.
///</summary>
publicclassExample
{
}
![Page 48: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/48.jpg)
TypeName PropertyDocumentationMustHaveValue
CheckId SA1609
Category DocumentationRules
![Page 49: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/49.jpg)
CauseTheXmlheaderdocumentationforaC#propertydoesnotcontaina<value>tag.
![Page 50: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/50.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Thedocumentationforpropertiesmayincludea<value>tag,whichdescribesthevalueheldbytheproperty.
Aviolationofthisruleoccurswhenthe<value>tagforapropertyismissing.
![Page 51: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/51.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addandfill-ina<value>tagwithinthedocumentationheaderfortheproperty.
Thefollowingexampleshowsapropertywhichcontainsa<value>tagwithinitsdocumentationheader.
///<summary>
///Getsthenameofthecustomer.
///</summary>
///<value>Thenameofthecustomer.</value>
publicboolName
{
get{returnthis.name;}
}
![Page 52: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/52.jpg)
TypeName PropertyDocumentationMustHaveValueText
CheckId SA1610
Category DocumentationRules
![Page 53: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/53.jpg)
CauseTheXmlheaderdocumentationforaC#propertycontainsanempty<value>tag.
![Page 54: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/54.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Thedocumentationforpropertiesmayincludea<value>tag,whichdescribesthevalueheldbytheproperty.
Aviolationofthisruleoccurswhenthe<value>tagforapropertyisempty.
![Page 55: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/55.jpg)
HowtoFixViolationsTofixaviolationofthisrule,fill-inadescriptionofthevalueheldbythepropertywithinthe<value>tag.
Example:
Thefollowingexampleshowsapropertywhichcontainsa<value>tagwithinitsdocumentationheader.
///<summary>
///Getsthenameofthecustomer.
///</summary>
///<value>Thenameofthecustomer.</value>
publicboolName
{
get{returnthis.name;}
}
![Page 56: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/56.jpg)
TypeName ElementParametersMustBeDocumented
CheckId SA1611
Category DocumentationRules
![Page 57: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/57.jpg)
CauseAC#method,constructor,delegateorindexerelementismissingdocumentationforoneormoreofitsparameters.
![Page 58: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/58.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifanelementcontainingparametersismissingdocumentationforoneormoreofitsparameters.
![Page 59: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/59.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorfill-indocumentationtextwithina<param>tagforeachparameterwithintheelement.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 60: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/60.jpg)
TypeName ElementParameterDocumentationMustMatchElementParameters
CheckId SA1612
Category DocumentationRules
![Page 61: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/61.jpg)
CauseThedocumentationdescribingtheparameterstoaC#method,constructor,delegateorindexerelementdoesnotmatchtheactualparametersontheelement.
![Page 62: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/62.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifthedocumentationforanelement’sparametersdoesnotmatchtheactualparametersontheelement,oriftheparameterdocumentationisnotlistedinthesameorderastheelement’sparameters.
![Page 63: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/63.jpg)
HowtoFixViolationsTofixaviolationofthisrule,correcttheparameterdocumentationsothatthe<param>tagsinthedocumentationappearinthesameorderastheelement’sparameters,andsothatthereisone<param>tagforeachparameterontheelement.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 64: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/64.jpg)
TypeName ElementParameterDocumentationMustDeclareParameterName
CheckId SA1613
Category DocumentationRules
![Page 65: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/65.jpg)
CauseA<param>tagwithinaC#element’sdocumentationheaderismissinganameattributecontainingthenameoftheparameter.
![Page 66: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/66.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifthedocumentationforanelementcontainsa<param>tagwhichismissinganameattribute,orwhichcontainsanemptynameattribute.
![Page 67: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/67.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorfill-inthenameattributeforthe<param>tagtoindicatethenameoftheparameterthatthedocumentationisfor.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 68: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/68.jpg)
TypeName ElementParameterDocumentationMustHaveText
CheckId SA1614
Category DocumentationRules
![Page 69: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/69.jpg)
CauseA<param>tagwithinaC#element’sdocumentationheaderisempty.
![Page 70: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/70.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifthedocumentationforanelementcontainsa<param>tagwhichisemptyanddoesnotcontainadescriptionoftheparameter.
![Page 71: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/71.jpg)
HowtoFixViolationsTofixaviolationofthisrule,fill-inadescriptionoftheparameterwithinthe<param>tag.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 72: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/72.jpg)
TypeName ElementReturnValueMustBeDocumented
CheckId SA1615
Category DocumentationRules
![Page 73: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/73.jpg)
CauseAC#elementismissingdocumentationforitsreturnvalue.
![Page 74: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/74.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifanelementcontainingareturnvalueismissinga<returns>tag.
![Page 75: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/75.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addandfill-indocumentationtextwithina<returns>tagdescribingthevaluereturnedfromtheelement.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 76: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/76.jpg)
TypeName ElementReturnValueDocumentationMustHaveText
CheckId SA1616
Category DocumentationRules
![Page 77: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/77.jpg)
CauseThe<returns>tagwithinaC#element’sdocumentationheaderisempty.
![Page 78: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/78.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifanelementcontainsanempty<returns>tag.
![Page 79: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/79.jpg)
HowtoFixViolationsTofixaviolationofthisrule,fill-indocumentationtextwithinthe<returns>tagdescribingthevaluereturnedfromtheelement.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 80: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/80.jpg)
TypeName VoidReturnValueMustNotBeDocumented
CheckId SA1617
Category DocumentationRules
![Page 81: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/81.jpg)
CauseAC#codeelementdoesnotcontainareturnvalue,orreturnsvoid,butthedocumentationheaderfortheelementcontainsa<returns>tag.
![Page 82: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/82.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifanelementwhichreturnsvoidcontainsa<returns>tagwithinitsdocumentationheader.
![Page 83: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/83.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removethe<returns>tagfromtheelement.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Printsthegivenname.
///</summary>
///<paramname="firstName">Thefirstname.</param>
///<paramname="lastName">Thelastname.</param>
publicvoidPrintNames(stringfirstName,stringlastName)
{
Console.WriteLine(firstName+""+lastName);
}
![Page 84: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/84.jpg)
TypeName GenericTypeParametersMustBeDocumented
CheckId SA1618
Category DocumentationRules
![Page 85: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/85.jpg)
CauseAgenericC#elementismissingdocumentationforoneormoreofitsgenerictypeparameters.
![Page 86: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/86.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifanelementcontaininggenerictypeparametersismissingdocumentationforoneormoreofitsgenerictypeparameters.
![Page 87: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/87.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorfill-indocumentationtextwithina<typeparam>tagforeachgenerictypeparameterontheelement.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Asamplegenericclass.
///</summary>
///<typeparamname="S">Thefirstgenerictypeparameter.</typeparam>
///<typeparamname="T">Thesecondgenerictypeparameter.</typeparam>
publicclassClass1<S,T>
{
}
![Page 88: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/88.jpg)
TypeName GenericTypeParametersMustBeDocumentedPartialClass
CheckId SA1619
Category DocumentationRules
![Page 89: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/89.jpg)
CauseAgeneric,partialC#elementismissingdocumentationforoneormoreofitsgenerictypeparameters,andthedocumentationfortheelementcontainsa<summary>tag.
![Page 90: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/90.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenageneric,partialelementismissingdocumentationforoneormoreofitsgenerictypeparameters,andthedocumentationfortheelementcontainsa<summary>tagratherthana<content>tag.
Whendocumentationisprovidedonmorethanonepartofthepartialclass,thedocumentationforthetwoclassesmaybemergedtogethertoformasinglesourceofdocumentation.Forexample,considerthefollowingtwopartsofapartialclass:
///<summary>
///DocumentationforthefirstpartofClass1.
///</summary>
publicpartialclassClass1
{
}
///<summary>
///DocumentationforthesecondpartofClass1.
///</summary>
publicpartialclassClass1
![Page 91: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/91.jpg)
{
}
Thesetwodifferentpartsofthesamepartialclasseachprovidedifferentdocumentationfortheclass.WhenthedocumentationforthisclassisbuiltintoanSDK,thetoolbuildingthedocumentationwilleitherchoosetouseonlyonepartofthedocumentationfortheclassandignoretheotherparts,or,insomecases,itmaymergethetwosourcesofdocumentationtogether,toformastringlike:“DocumentationforthefirstpartofClass1.DocumentationforthesecondpartofClass1.”
Forthesereasons,itcanbeproblematictoprovideSDKdocumentationonmorethanonepartofthepartialclass.However,itisstilladvisabletodocumenteachpartoftheclass,toincreasethereadabilityandmaintainabilityofthecode,andStyleCopwillrequirethateachpartoftheclasscontainheaderdocumentation.
Thisproblemissolvedthroughtheuseofthe<content>tag,whichcanreplacethe<summary>tagforpartialclasses.TherecommendedpracticefordocumentingpartialclassesistoprovidetheofficialSDKdocumentationfortheclassonthemainpartofthepartialclass.Thisdocumentationshouldbewrittenusingthestandard<summary>tag.Allotherpartsofthepartialclassshouldomitthe<summary>tagcompletely,andreplaceitwitha<content>tag.ThisallowsthedevelopertodocumentallpartsofthepartialclasswhilestillcentralizingalloftheofficialSDKdocumentationfortheclassontoonepartoftheclass.The<content>tagswillbeignoredbytheSDKdocumentationtools.
Whenagenericelementcontainsa<summary>tagwithinitsdocumentationheader,StyleCopassumesthatthisisthemainpartoftheclass,andrequirestheheadertocontain<typeparam>tagsforeachofthegenerictypeparametersontheclass.However,ifthedocumentationheaderfortheclasscontainsa<content>tagratherthana<summary>tag,StyleCopwillassumethatthegenerictypeparametersaredefinedonanotherpartoftheclass,andwillnotrequire<typeparam>tagsonthispartoftheclass.
![Page 92: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/92.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorfill-indocumentationtextwithina<typeparam>tagforeachgenerictypeparameterontheelement,orchangethe<summary>tagtoa<content>tagifthisisnotthemainpartofthepartialclass.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Asamplegenericclass.
///</summary>
///<typeparamname="S">Thefirstgenerictypeparameter.</typeparam>
///<typeparamname="T">Thesecondgenerictypeparameter.</typeparam>
publicclassClass1<S,T>
{
}
![Page 93: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/93.jpg)
TypeName GenericTypeParameterDocumentationMustMatchTypeParameters
CheckId SA1620
Category DocumentationRules
![Page 94: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/94.jpg)
CauseThe<typeparam>tagswithintheXmlheaderdocumentationforagenericC#elementdonotmatchthegenerictypeparametersontheelement.
![Page 95: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/95.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifthe<typeparam>tagswithintheelement’sheaderdocumentationdonotmatchthegenerictypeparametersontheelement,ordonotappearinthesameorderastheelement’stypeparameters.
![Page 96: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/96.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addandfill-inone<typeparam>tagforeachgenerictypeparameterontheelement,andmakesurethatthe<typeparam>tagsappearinthesameorderastheelement’stypeparameters.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Asamplegenericclass.
///</summary>
///<typeparamname="S">Thefirstgenerictypeparameter.</typeparam>
///<typeparamname="T">Thesecondgenerictypeparameter.</typeparam>
publicclassClass1<S,T>
{
}
![Page 97: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/97.jpg)
TypeName GenericTypeParameterDocumentationMustDeclareParameterName
CheckId SA1621
Category DocumentationRules
![Page 98: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/98.jpg)
CauseA<typeparam>tagwithintheXmlheaderdocumentationforagenericC#elementismissinganameattribute,orcontainsanemptynameattribute.
![Page 99: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/99.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursiftheelementcontainsa<typeparam>tagwithinitsXmlheaderdocumentationwhichdoesnotdeclarethenameofthetypeparameter.
![Page 100: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/100.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorfill-inthenameattributeforeach<typeparam>tag,indicatingthenameofthetypeparameterthatthedocumentationisfor.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Asamplegenericclass.
///</summary>
///<typeparamname="S">Thefirstgenerictypeparameter.</typeparam>
///<typeparamname="T">Thesecondgenerictypeparameter.</typeparam>
publicclassClass1<S,T>
{
}
![Page 101: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/101.jpg)
TypeName GenericTypeParameterDocumentationMustHaveText
CheckId SA1622
Category DocumentationRules
![Page 102: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/102.jpg)
CauseA<typeparam>tagwithintheXmlheaderdocumentationforagenericC#elementisempty.
![Page 103: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/103.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursiftheelementcontainsanempty<typeparam>tagwithinitsXmlheaderdocumentation.
![Page 104: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/104.jpg)
HowtoFixViolationsTofixaviolationofthisrule,fill-ineach<typeparam>tagwithinadescriptionofthegenerictypeparameter.
Thefollowingexampleshowsamethodwithavaliddocumentationheader:
///<summary>
///Asamplegenericclass.
///</summary>
///<typeparamname="S">Thefirstgenerictypeparameter.</typeparam>
///<typeparamname="T">Thesecondgenerictypeparameter.</typeparam>
publicclassClass1<S,T>
{
}
![Page 105: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/105.jpg)
TypeName PropertySummaryDocumentationMustMatchAccessors
CheckId SA1623
Category DocumentationRules
![Page 106: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/106.jpg)
CauseThedocumentationtextwithinaC#property’s<summary>tagdoesnotmatchtheaccessorswithintheproperty.
![Page 107: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/107.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccursifaproperty’ssummarydocumentationdoesnotmatchtheaccessorswithintheproperty.
Theproperty’ssummarytextmustbeginwithwordingdescribingthetypesofaccessorsexposedwithintheproperty.Ifthepropertycontainsonlyagetaccessor,thesummarymustbeginwiththeword“Gets”.Ifthepropertycontainsonlyasetaccessor,thesummarymustbeginwiththeword“Sets”.Ifthepropertyexposesbothagetandsetaccessor,thesummarytextmustbeginwith“Getsorsets”.
Forexample,considerthefollowingproperty,whichexposesbothagetandsetaccessor.Thesummarytextbeginswiththewords“Getsorsets”.
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
publicstringName
{
get{returnthis.name;}
set{this.name=value;}
}
IfthepropertyreturnsaBooleanvalue,anadditionalruleisapplied.ThesummarytextforBooleanpropertiesmustcontainthewords“Getsavalueindicatingwhether”,“Setsavalueindicatingwhether”,or“Getsorsetsavalue
![Page 108: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/108.jpg)
indicatingwhether”.Forexample,considerthefollowingBooleanproperty,whichonlyexposesagetaccessor:
///<summary>
///Getsavalueindicatingwhethertheitemisenabled.
///</summary>
publicboolEnabled
{
get{returnthis.enabled;}
}
Insomesituations,thesetaccessorforapropertycanhavemorerestrictedaccessthanthegetaccessor.Forexample:
///<summary>
///Getsthenameofthecustomer.
///</summary>
publicstringName
{
get{returnthis.name;}
privateset{this.name=value;}
}
Inthisexample,thesetaccessorhasbeengivenprivateaccess,meaningthatitcanonlybeaccessedbylocalmembersoftheclassinwhichitiscontained.Thegetaccessor,however,inheritsitsaccessfromtheparentproperty,thusitcanbe
![Page 109: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/109.jpg)
accessedbyanycaller,sincethepropertyhaspublicaccess.
>Inthiscase,thedocumentationsummarytextshouldavoidreferringtothesetaccessor,sinceitisnotvisibletoexternalcallers.
StyleCopappliesaseriesofrulestodeterminewhenthesetaccessorshouldbereferencedintheproperty’ssummarydocumentation.Ingeneral,theserulesrequirethesetaccessortobereferencedwheneveritisvisibletothesamesetofcallersasthegetaccessor,orwheneveritisvisibletoexternalclassesorinheritingclasses.
Thespecificrulesfordeterminingwhethertoincludethesetaccessorintheproperty’ssummarydocumentationare:
1.Thesetaccessorhasthesameaccesslevelasthegetaccessor.Forexample:
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
protectedstringName
{
get{returnthis.name;}
set{this.name=value;}
}
2.Thepropertyisonlyinternallyaccessiblewithintheassembly,andthesetaccessoralsohasinternalaccess.Forexample:
internalclassClass1
{
///<summary>
![Page 110: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/110.jpg)
///Getsorsetsthenameofthecustomer.
///</summary>
protectedstringName
{
get{returnthis.name;}
internalset{this.name=value;}
}
}
internalclassClass1
{
publicclassClass2
{
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
publicstringName
{
get{returnthis.name;}
internalset{this.name=value;}
![Page 111: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/111.jpg)
}
}
}
3.Thepropertyisprivateoriscontainedbeneathaprivateclass,andthesetaccessorhasanyaccessmodifierotherthanprivate.Intheexamplebelow,theaccessmodifierdeclaredonthesetaccessorhasnomeaning,sincethesetaccessoriscontainedwithinaprivateclassandthuscannotbeseenbyotherclassesoutsideofClass1.Thiseffectivelygivesthesetaccessorthesameaccesslevelasthegetaccessor.
publicclassClass1
{
privateclassClass2
{
publicclassClass3
{
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
publicstringName
{
get{returnthis.name;}
internalset{this.name=value;}
![Page 112: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/112.jpg)
}
}
}
}
4.Wheneverthesetaccessorhasprotectedorprotectedinternalaccess,itshouldbereferencedinthedocumentation.Aprotectedorprotectedinternalsetaccessorcanalwaysbeenseenbyaclassinheritingfromtheclasscontainingtheproperty.
internalclassClass1
{
publicclassClass2
{
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
internalstringName
{
get{returnthis.name;}
protectedset{this.name=value;}
}
}
![Page 113: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/113.jpg)
privateclassClass3:Class2
{
publicClass3(stringname){this.Name=name;}
}
}
![Page 114: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/114.jpg)
HowtoFixViolationsTofixaviolationofthisrule,updatetheproperty’ssummarytextsothatthedescriptionbeginswiththeproperwording,dependinguponthetypeofthepropertyandthetypesofaccessorswithintheproperty.
![Page 115: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/115.jpg)
TypeName PropertySummaryDocumentationMustOmitSetAccessorWithRestrictedAccess
CheckId SA1624
Category DocumentationRules
![Page 116: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/116.jpg)
CauseThedocumentationtextwithinaC#property’s<summary>tagtakesintoaccountalloftheaccessorswithintheproperty,butoneoftheaccessorshaslimitedaccess.
![Page 117: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/117.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenoneoftheaccessorswithinthepropertyhaslimitedaccess(usuallythesetaccessor),butthesummarydocumentationtextforthepropertystillreferstobothaccessors.
Normally,aproperty’ssummarytextmustbeginwithwordingdescribingthetypesofaccessorsexposedwithintheproperty.Ifthepropertycontainsonlyagetaccessor,thesummarymustbeginwiththeword“Gets”.Ifthepropertycontainsonlyasetaccessor,thesummarymustbeginwiththeword“Sets”.Ifthepropertyexposesbothagetandsetaccessor,thesummarytextmustbeginwith“Getsorsets”.
However,whenanaccessorwithinthepropertyisgivenanaccesslevelwhichismorelimitedthantheaccessleveloftheproperty,thisaccessorshouldbeomittedfromthesummarydocumentation.
Itcansometimesbenon-obviouswhetherthesetaccessorwithinapropertyisactuallylessaccessiblethanthegetaccessor.Forexample,considerthecasewhereapublicpropertyiscontainedwithinaninternalclass,andthesetaccessorisgiveninternalaccessor.Ineffect,boththegetandsetaccessorshavethesameaccesslevel.Inthiscase,thesummarydocumentationshouldrefertoboththegetandsetaccessors,sincetheyeffectivelyhavethesameaccesslevel.
Insomesituations,thesetaccessorforapropertycanhavemorerestrictedaccessthanthegetaccessor.Forexample:
///<summary>
///Getsthenameofthecustomer.
///</summary>
publicstringName
![Page 118: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/118.jpg)
{
get{returnthis.name;}
privateset{this.name=value;}
}
Inthisexample,thesetaccessorhasbeengivenprivateaccess,meaningthatitcanonlybeaccessedbylocalmembersoftheclassinwhichitiscontained.Thegetaccessor,however,inheritsitsaccessfromtheparentproperty,thusitcanbeaccessedbyanycaller,sincethepropertyhaspublicaccess.
Inthiscase,thedocumentationsummarytextshouldavoidreferringtothesetaccessor,sinceitisnotvisibletoexternalcallers.
StyleCopappliesaseriesofrulestodeterminewhenthesetaccessorshouldbereferencedintheproperty’ssummarydocumentation.Ingeneral,theserulesrequirethesetaccessortobereferencedwheneveritisvisibletothesamesetofcallersasthegetaccessor,orwheneveritisvisibletoexternalclassesorinheritingclasses.
Thespecificrulesfordeterminingwhethertoincludethesetaccessorintheproperty’ssummarydocumentationare:
1.Thesetaccessorhasthesameaccesslevelasthegetaccessor.Forexample:
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
protectedstringName
{
get{returnthis.name;}
set{this.name=value;}
}
![Page 119: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/119.jpg)
2.Thepropertyisonlyinternallyaccessiblewithintheassembly,andthesetaccessoralsohasinternalaccess.Forexample:
internalclassClass1
{
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
protectedstringName
{
get{returnthis.name;}
internalset{this.name=value;}
}
}
internalclassClass1
{
publicclassClass2
{
///<summary>
![Page 120: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/120.jpg)
///Getsorsetsthenameofthecustomer.
///</summary>
publicstringName
{
get{returnthis.name;}
internalset{this.name=value;}
}
}
}
3.Thepropertyisprivateoriscontainedbeneathaprivateclass,andthesetaccessorhasanyaccessmodifierotherthanprivate.Intheexamplebelow,theaccessmodifierdeclaredonthesetaccessorhasnomeaning,sincethesetaccessoriscontainedwithinaprivateclassandthuscannotbeseenbyotherclassesoutsideofClass1.Thiseffectivelygivesthesetaccessorthesameaccesslevelasthegetaccessor.
publicclassClass1
{
privateclassClass2
{
publicclassClass3
{
![Page 121: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/121.jpg)
///<summary>
///Getsorsetsthenameofthecustomer.
///</summary>
publicstringName
{
get{returnthis.name;}
internalset{this.name=value;}
}
}
}
}
4.Wheneverthesetaccessorhasprotectedorprotectedinternalaccess,itshouldbereferencedinthedocumentation.Aprotectedorprotectedinternalsetaccessorcanalwaysbeenseenbyaclassinheritingfromtheclasscontainingtheproperty.
internalclassClass1
{
publicclassClass2
{
///<summary>
![Page 122: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/122.jpg)
///Getsorsetsthenameofthecustomer.
///</summary>
internalstringName
{
get{returnthis.name;}
protectedset{this.name=value;}
}
}
privateclassClass3:Class2
{
publicClass3(stringname){this.Name=name;}
}
}
![Page 123: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/123.jpg)
HowtoFixViolationsTofixaviolationofthisrule,updatetheproperty’ssummarytextandremovewordingwhichreferstothelimitedaccessaccessor.
![Page 124: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/124.jpg)
TypeName ElementDocumentationMustNotBeCopiedAndPasted
CheckId SA1625
Category DocumentationRules
![Page 125: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/125.jpg)
CauseTheXmldocumentationforaC#elementcontainstwoormoreidenticalentries,indicatingthatthedocumentationhasbeencopiedandpasted.Thiscansometimesindicateinvalidorpoorlywrittendocumentation.
![Page 126: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/126.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenanelementcontainstwoormoreidenticaldocumentationtexts.Forexample:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Partofthename.</param>
///<paramname="lastName">Partofthename.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
Insomecases,amethodmaycontainoneormoreparameterswhicharenotusedwithinthebodyofthemethod.Inthiscase,thedocumentationfortheparametercanbesetto"Theparameterisnotused."StyleCopwillallowmultipleparameterstocontainidenticaldocumentationaslongasthedocumentationstringis"Theparameterisnotused."
![Page 127: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/127.jpg)
HowtoFixViolationsTofixaviolationofthisrule,editthedocumentationfortheelementandensurethateachoftheindividualdocumentationtextsareunique.Forexample:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 128: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/128.jpg)
TypeName SingleLineCommentsMustNotUseDocumentationStyleSlashes
CheckId SA1626
Category DocumentationRules
![Page 129: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/129.jpg)
CauseTheC#codecontainsasingle-linecommentwhichbeginswiththreeforwardslashesinarow.
![Page 130: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/130.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainsasingle-linecommentwhichbeginswiththreeslashes.CommentsbeginningwiththreeslashesarereservedforXmldocumentationheaders.Single-linecommentsshouldbeginwithonlytwoslashes.Whencommentingoutlinesofcode,itisadvisabletobeginthecommentwithfourslashestodifferentiateitfromnormalcomments.Forexample:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Partofthename.</param>
///<paramname="lastName">Partofthename.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
Alegalcommentbeginningwithtwoslashes:
//Jointhenamestogether.
stringfullName=firstName+""+lastName;
Anillegalcommentbeginningwiththreeslashes:
///Trimthename.
fullName=fullName.Trim();
![Page 131: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/131.jpg)
Alineofcommented-outcodebeginningwithfourslashes:
////fullName=asfd;
returnfullName;
}
![Page 132: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/132.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removeaslashfromthebeginningofthecommentsothatitbeginswithonlytwoslashes.
![Page 133: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/133.jpg)
TypeName DocumentationTextMustNotBeEmpty
CheckId SA1627
Category DocumentationRules
![Page 134: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/134.jpg)
CauseTheXmlheaderdocumentationforaC#codeelementcontainsanemptytag.
![Page 135: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/135.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenthedocumentationheaderforanelementcontainsanemptytag.Forexample:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName"></param>
///<paramname="lastName">Partofthename.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
...
}
![Page 136: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/136.jpg)
HowtoFixViolationsTofixaviolationofthisrule,adddocumentationtextwithintheemptytag.
![Page 137: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/137.jpg)
TypeName DocumentationTextMustBeginWithACapitalLetter
CheckId SA1628
Category DocumentationRules
![Page 138: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/138.jpg)
CauseAsectionoftheXmlheaderdocumentationforaC#elementdoesnotbeginwithacapitalletter.
![Page 139: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/139.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenpartofthedocumentationdoesnotbeginwithacapitalletter.Forexample,thesummarytextinthedocumentationbelowbeginswithalower-caseletter:
///<summary>
///joinsafirstnameandalastnametogetherintoasinglestring.
///</summary>
///<paramname="firstName">Thefirstname.</param>
///<paramname="lastName">Thelastname.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
...
}
![Page 140: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/140.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatallsectionsofthedocumentationbeginwithacapitalletter.
![Page 141: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/141.jpg)
TypeName DocumentationTextMustEndWithAPeriod
CheckId SA1629
Category DocumentationRules
![Page 142: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/142.jpg)
CauseAsectionoftheXmlheaderdocumentationforaC#elementdoesnotendwithaperiod(alsoknownasafullstop).
![Page 143: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/143.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenpartofthedocumentationdoesnotendwithaperiod.Forexample,thesummarytextinthedocumentationbelowdoesnotendwithaperiod:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring
///</summary>
///<paramname="firstName">Thefirstname.</param>
///<paramname="lastName">Thelastname.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
...
}
![Page 144: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/144.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatallsectionsofthedocumentationendwithaperiod.
![Page 145: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/145.jpg)
TypeName DocumentationTextMustContainWhitespace
CheckId SA1630
Category DocumentationRules
![Page 146: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/146.jpg)
CauseAsectionoftheXmlheaderdocumentationforaC#elementdoesnotcontainanywhitespacebetweenwords.
![Page 147: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/147.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenpartofthedocumentationdoescontainanywhitespacebetweenwords.Thiscanindicatepoorlywrittenorpoorlyformatteddocumentation.Forexample:
///<summary>
///Joinsnames
///</summary>
///<paramname="firstName">First</param>
///<paramname="lastName">Last</param>
///<returns>Name</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
...
}
![Page 148: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/148.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatallsectionsofthedocumentationcontainatleastoneinstanceofwhitespacebetweenwords.
![Page 149: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/149.jpg)
TypeName DocumentationTextMustMeetCharacterPercentage
CheckId SA1631
Category DocumentationRules
![Page 150: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/150.jpg)
CauseAsectionoftheXmlheaderdocumentationforaC#elementdoesnotcontainenoughalphabeticcharacters.
![Page 151: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/151.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenpartofthedocumentationdoescontainenoughcharacters.Thisruleiscalculatedbycountingthenumberofalphabeticcharactersandnumberswithinthedocumentationtext,andcomparingitagainstthenumberofsymbolsandothernon-alphabeticcharacters.Ifthepercentageofnon-alphabeticcharactersistoohigh,thisgenerallyindicatespoorlyformatteddocumentationwhichwillbedifficulttoread.Forexample,considerthefollowsummarydocumentation:
///<summary>
///@)$(*Aname--------
///</summary>
publicclassName
{
...
}
![Page 152: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/152.jpg)
HowtoFixViolationsTofixaviolationofthisrule,rewritethedocumentationtextusinggrammaticallyproperlanguage,andensurethattheratioofsymbolsversuscharactersinthetextisnottoogreat.
![Page 153: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/153.jpg)
TypeName DocumentationTextMustMeetMinimumCharacterLength
CheckId SA1632
Category DocumentationRules
![Page 154: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/154.jpg)
CauseFromStyleCop4.5thisruleisdisabledbydefault.
AsectionoftheXmlheaderdocumentationforaC#elementistooshort.
![Page 155: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/155.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenpartofthedocumentationistooshort.Thiscanoftenindicatethatthedocumentationisnotdescriptive.Forexample:
///<summary>
///Aname
///</summary>
publicclassName
{
...
}
![Page 156: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/156.jpg)
HowtoFixViolationsTofixaviolationofthisrule,rewritethedocumentationtextusinggrammaticallyproperanddescriptivelanguage.Inmostcases,doingsowillcausethelengthofthedocumentationtexttobegreaterthantheminimumlengthwhichcausesthisruletofire.
![Page 157: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/157.jpg)
TypeName FileMustHaveHeader
CheckId SA1633
Category DocumentationRules
![Page 158: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/158.jpg)
CauseAC#codefileismissingastandardfileheader.
![Page 159: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/159.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaC#sourcefileismissingafileheader.Thefileheadermustbeginonthefirstlineofthefile,andmustbeformattedasablockofcommentscontainingXml,asfollows:
//-----------------------------------------------------------------------
//<copyrightfile="NameOfFile.cs"company="CompanyName">
//Companycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
Forexample,afilecalledWidget.csfromafictionalcompanycalledSprocketEnterprisesshouldcontainafileheadersimilartothefollowing:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="SprocketEnterprises">
//Copyright(c)SprocketEnterprises.Allrightsreserved.
//</copyright>
//-----------------------------------------------------------------------
Thedashedlinesatthetopandbottomoftheheaderarenotstrictlynecessary,sotheheadercouldbewrittenas:
//<copyrightfile="Widget.cs"company="SprocketEnterprises">
//Copyright(c)SprocketEnterprises.Allrightsreserved.
//</copyright>
Itispossibletoaddadditionaltags,althoughtheywillnotbecheckedorenforcedbyStyleCop:
![Page 160: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/160.jpg)
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="SprocketEnterprises">
//Copyright(c)SprocketEnterprises.Allrightsreserved.
//</copyright>
//<author>JohnDoe</author>
//-----------------------------------------------------------------------
Afilethatiscompletelyauto-generatedbyatool,andwhichshouldnotbecheckedorenforcedbyStyleCop,canincludean“auto-generated”headerratherthanthestandardfileheader.ThiswillcauseStyleCoptoignorethefile.Thistypeofheadershouldneverbeplacedontopofamanuallywrittencodefile.
//<auto-generated/>
namespaceSample.Something
{
//Thecontentsofthisfilearecompletelyauto-generatedbyatool.
}
![Page 161: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/161.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addastandardfileheaderatthetopofthefile.
![Page 162: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/162.jpg)
TypeName FileHeaderMustShowCopyright
CheckId SA1634
Category DocumentationRules
![Page 163: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/163.jpg)
CauseThefileheaderatthetopofaC#codefileismissingacopyrighttag.
![Page 164: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/164.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefileheaderatthetopofaC#fileismissingacopyrighttag.Forexample:
//-----------------------------------------------------------------------
//<Tag>Afileheaderwhichdoesnotcontainacopyrighttag</Tag>
//-----------------------------------------------------------------------
Afileheadershouldincludeacopyrighttag,asfollows:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
![Page 165: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/165.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addastandardcopyrighttagtothefileheader.
![Page 166: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/166.jpg)
TypeName FileHeaderMustHaveCopyrightText
CheckId SA1635
Category DocumentationRules
![Page 167: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/167.jpg)
CauseThefileheaderatthetopofaC#codefileismissingcopyrighttext.
![Page 168: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/168.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefileheaderatthetopofaC#filedoesnotcontaintextwithinitscopyrighttag.Forexample:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="SprocketEnterprises">
//</copyright>
//-----------------------------------------------------------------------
Afileheadershouldincludecopyrighttext,asfollows:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="SprocketEnterprises">
//Copyright(c)SprocketEnterprises.Allrightsreserved.
//</copyright>
//-----------------------------------------------------------------------
![Page 169: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/169.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addyourcompany’sstandardcopyrighttexttothecopyrighttag.
![Page 170: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/170.jpg)
TypeName FileHeaderCopyrightTextMustMatch
CheckId SA1636
Category DocumentationRules
![Page 171: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/171.jpg)
CauseThefileheaderatthetopofaC#codefiledoesnotcontaintheappropriatecopyrighttext.
![Page 172: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/172.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefileheaderatthetopofaC#filedoesnotcontainthecopyrighttextthathasbeenspecifiedfortheproject.Toenablethisrule,navigatetotheStyleCopsettingsfortheprojectandchangetotheCompanyInformationtab,asshownbelow:
Checkthecheckboxatthetopofthesettingspage,andfillintherequiredcopyrighttextforyourcompany.ClickOKtosavethesettings.Withthesesettingsinplace,everyfilewithintheprojectmustcontaintherequiredcopyrighttextwithinitsfileheadercopyrighttag,asshownintheexamplebelow:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
![Page 173: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/173.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addyourcompany’sstandardcopyrighttexttothefileheadercopyrighttag.
![Page 174: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/174.jpg)
TypeName FileHeaderMustContainFileName
CheckId SA1637
Category DocumentationRules
![Page 175: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/175.jpg)
CauseThefileheaderatthetopofaC#codefileismissingthefilename.
![Page 176: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/176.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefileheaderatthetopofaC#filedoesnotcontainavalidfilenametag.Forexample:
//-----------------------------------------------------------------------
//<copyrightcompany="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
Afileheadershouldincludeafiletagcontainingthenameofthefile,asfollows:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
![Page 177: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/177.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addafiletagcontainingthenameofthefile.
![Page 178: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/178.jpg)
TypeName FileHeaderFileNameDocumentationMustMatchFileName
CheckId SA1638
Category DocumentationRules
![Page 179: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/179.jpg)
CauseThefiletagwithinthefileheaderatthetopofaC#codefiledoesnotcontainthenameofthefile.
![Page 180: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/180.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefiletagwithinthefileheaderatthetopofaC#filedoesnotcontainthenameofthefile.Forexample,consideraC#sourcefilenamedFile1.cs,withthefollowingheader:
//-----------------------------------------------------------------------
//<copyrightfile="File2.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
Aviolationofthisrulewouldoccur,sincethefiletagdoesnotcontainthecorrectnameofthefile.Theheadershouldbewrittenas:
//-----------------------------------------------------------------------
//<copyrightfile="File1.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
![Page 181: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/181.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addthenameofthefiletothefiletag.
![Page 182: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/182.jpg)
TypeName FileHeaderMustHaveSummary
CheckId SA1639
Category DocumentationRules
![Page 183: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/183.jpg)
CauseThefileheaderatthetopofaC#codefiledoesnotcontainafilled-insummarytag.
![Page 184: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/184.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefileheaderatthetopofaC#filedoesnotcontainavalidsummarytag.Thisruleisdisabledbydefault.
Forexample:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
Ifthisruleisenabled,thefileheadershouldcontainasummarytag.Forexample:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//<summary>ThisistheWidgetclass.</summary>//-----------------------------------------------------------------------
![Page 185: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/185.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addandfill-inasummarytagdescribingthecontentsofthefile.
![Page 186: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/186.jpg)
TypeName FileHeaderMustHaveValidCompanyText
CheckId SA1640
Category DocumentationRules
![Page 187: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/187.jpg)
CauseThefileheaderatthetopofaC#codefiledoesnotcontaincompanynametext.
![Page 188: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/188.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefileheaderatthetopofaC#filedoesnotcontainacompanytagwithcompanynametext.Forexample:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
Thecompanyattributeshouldhavetextinit.Forexample:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
![Page 189: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/189.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addandfill-inacompanyattributecontainingthenameofthecompany.
![Page 190: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/190.jpg)
TypeName FileHeaderCompanyNameTextMustMatch
CheckId SA1641
Category DocumentationRules
![Page 191: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/191.jpg)
CauseThefileheaderatthetopofaC#codefiledoesnotcontaintheappropriatecompanynametext.
![Page 192: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/192.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefileheaderatthetopofaC#filedoesnotcontainthecompanynametextthathasbeenspecifiedfortheproject.Toenablethisrule,navigatetotheStyleCopsettingsfortheprojectandchangetotheCompanyInformationtab,asshownbelow:
Checkthecheckboxatthetopofthesettingspage,andfillintherequiredcompanynametextforyourcompany.ClickOKtosavethesettings.Withthesesettingsinplace,everyfilewithintheprojectmustcontaintherequiredcompanynametextwithinitsfileheadercopyrighttag,asshownintheexamplebelow:
//-----------------------------------------------------------------------
//<copyrightfile="Widget.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
![Page 193: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/193.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addyourcompany’sstandardcompanynametexttothefileheadercopyrighttag.
![Page 194: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/194.jpg)
TypeName ConstructorSummaryDocumentationMustBeginWithStandardText
CheckId SA1642
Category DocumentationRules
![Page 195: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/195.jpg)
CauseTheXmldocumentationheaderforaC#constructordoesnotcontaintheappropriatesummarytext.
![Page 196: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/196.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenthesummarytagwithinthedocumentationheaderforaconstructordoesnotbeginwiththepropertext.
Theruleisintendedtostandardizethesummarytextforaconstructorbasedontheaccessleveloftheconstructor.Thesummaryforanon-privateinstanceconstructormustbeginwith“Initializesanewinstanceofthe{classname}class.”Forexample,thefollowingshowstheconstructorfortheCustomerclass.
///<summary>
///InitializesanewinstanceoftheCustomerclass.
///</summary>
publicCustomer()
{
}
Itispossibletoembedothertagsintothesummarytext.Forexample:
///<summary>
///Initializesanewinstanceofthe<seecref="Customer"/>class.
///</summary>
publicCustomer()
![Page 197: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/197.jpg)
{
}
Iftheclasscontainsgenericparameters,thesecanbeannotatedwithinthecreflinkusingeitherofthefollowingtwoformats:
///<summary>
///Initializesanewinstanceofthe<seecref="Customer`1"/>class.
///</summary>
publicCustomer()
{
}
///<summary>
///Initializesanewinstanceofthe<seecref="Customer{T}"/>class.
///</summary>
publicCustomer()
{
}
Iftheconstructorisstatic,thesummarytextshouldbeginwith“Initializesstaticmembersofthe{classname}class.”Forexample:
///<summary>
///InitializesstaticmembersoftheCustomerclass.
![Page 198: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/198.jpg)
///</summary>
publicstaticCustomer()
{
}
Privateinstanceconstructorsmustusethesummarytext“Preventsadefaultinstanceofthe{classname}classfrombeingcreated.”
///<summary>
///PreventsadefaultinstanceoftheCustomerclassfrombeingcreated.
///</summary>
privateCustomer()
{
}
![Page 199: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/199.jpg)
HowtoFixViolationsTofixaviolationofthisrule,editthesummarytextfortheconstructorasdescribedabove.
![Page 200: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/200.jpg)
TypeName DestructorSummaryDocumentationMustBeginWithStandardText
CheckId SA1643
Category DocumentationRules
![Page 201: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/201.jpg)
CauseTheXmldocumentationheaderforaC#finalizerdoesnotcontaintheappropriatesummarytext.
![Page 202: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/202.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenthesummarytagwithinthedocumentationheaderforafinalizerdoesnotbeginwiththepropertext.
Theruleisintendedtostandardizethesummarytextforafinalizer.Thesummaryforafinalizermustbeginwith“Finalizesaninstanceofthe{classname}class.”Forexample,thefollowingshowsthefinalizerfortheCustomerclass.
///<summary>
///FinalizesaninstanceoftheCustomerclass.
///</summary>
~Customer()
{
}
Itispossibletoembedothertagsintothesummarytext.Forexample:
///<summary>
///Finalizesaninstanceofthe<seecref="Customer"/>class.
///</summary>
~Customer()
{
![Page 203: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/203.jpg)
}Iftheclasscontainsgenericparameters,thesecanbeannotatedwithinthecreflinkusingeitherofthefollowingtwoformats:
///<summary>
///Initializesanewinstanceofthe<seecref="Customer`1"/>class.
///</summary>
publicCustomer()
{
}
///<summary>
///Initializesanewinstanceofthe<seecref="Customer{T}"/>class.
///</summary>
publicCustomer()
{
}
![Page 204: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/204.jpg)
HowtoFixViolationsTofixaviolationofthisrule,editthesummarytextforthefinalizerasdescribedabove.
![Page 205: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/205.jpg)
TypeName DocumentationHeadersMustNotContainBlankLines
CheckId SA1644
Category DocumentationRules
![Page 206: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/206.jpg)
CauseAsectionwithintheXmldocumentationheaderforaC#elementcontainsblanklines.
![Page 207: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/207.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Aviolationofthisruleoccurswhenthedocumentationheadercontainsoneormoreblanklineswithinasectionofdocumentation.Forexample:
///<summary>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///
///Usesasimpleformofstringconcatenation.
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
Ratherthaninsertingblanklinesintothedocumentation,usethe<para>tagtodenoteparagraphs.Forexample:
///<summary>
![Page 208: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/208.jpg)
///<para>
///Joinsafirstnameandalastnametogetherintoasinglestring.
///</para><para>
///Usesasimpleformofstringconcatenation.
///</para>
///</summary>
///<paramname="firstName">Thefirstnametojoin.</param>
///<paramname="lastName">Thelastnametojoin.</param>
///<returns>Thejoinednames.</returns>
publicstringJoinNames(stringfirstName,stringlastName)
{
returnfirstName+""+lastName;
}
![Page 209: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/209.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklinesfromthedocumentationheader,andoptionallyreplacethemwith<para/>tags.
![Page 210: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/210.jpg)
TypeName IncludedDocumentationFileDoesNotExist
CheckId SA1645
Category DocumentationRules
![Page 211: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/211.jpg)
CauseAnincludedXmldocumentationfiledoesnotexist.
![Page 212: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/212.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Asanalternativetoauthoringdocumentationdirectlywithinthecodefile,itispossibletoplacedocumentationformultipleelementswithinaseparateXmlfile,andthenreferenceasectionofthatfilewithinanelement'sdocumentationheader.Thiscausesthecompilertoimportthedocumentationforthatelementfromtheincludeddocument.Forexample:
///<includefile="IncludedDocumentation.xml"path="root/EnabledMethodDocs"/>publicboolEnabled(booltrue)
{
}
Aviolationofthisruleoccurswhentheincludedfiledoesnotexistatthegivenlocation,orcannotbeloaded.
![Page 213: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/213.jpg)
HowtoFixViolationsTofixaviolationofthisrule,correctthepathtotheincludeddocumentationfiletopointtoavalidfilelocation.
![Page 214: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/214.jpg)
TypeName IncludedDocumentationXPathDoesNotExist
CheckId SA1646
Category DocumentationRules
![Page 215: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/215.jpg)
CauseAnincludedXmldocumentationlinkcontainsaninvalidpath.
![Page 216: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/216.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Asanalternativetoauthoringdocumentationdirectlywithinthecodefile,itispossibletoplacedocumentationformultipleelementswithinaseparateXmlfile,andthenreferenceasectionofthatfilewithinanelement'sdocumentationheader.Thiscausesthecompilertoimportthedocumentationforthatelementfromtheincludeddocument.Forexample:
///<includefile="IncludedDocumentation.xml"path="root/EnabledMethodDocs"/>publicboolEnabled(booltrue)
{
}
Aviolationofthisruleoccurswhenthepathattributedoesnotlinktoavalidpathwithintheincludeddocumentationfile.
![Page 217: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/217.jpg)
HowtoFixViolationsTofixaviolationofthisrule,correctthevalueofthepathattributetopointtoavalidpathwithinthefile.
![Page 218: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/218.jpg)
TypeName IncludeNodeDoesNotContainValidFileAndPath
CheckId SA1647
Category DocumentationRules
![Page 219: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/219.jpg)
CauseAnincludetagwithinanXmldocumentationheaderdoesnotcontainvalidfileandpathattribute.
![Page 220: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/220.jpg)
RuleDescriptionC#syntaxprovidesamechanismforinsertingdocumentationforclassesandelementsdirectlyintothecode,throughtheuseofXmldocumentationheaders.Foranintroductiontotheseheadersandadescriptionoftheheadersyntax,seethefollowingarticle:http://msdn.microsoft.com/en-us/magazine/cc302121.aspx.
Asanalternativetoauthoringdocumentationdirectlywithinthecodefile,itispossibletoplacedocumentationformultipleelementswithinaseparateXmlfile,andthenreferenceasectionofthatfilewithinanelement'sdocumentationheader.Thiscausesthecompilertoimportthedocumentationforthatelementfromtheincludeddocument.Forexample:
///<includefile="IncludedDocumentation.xml"path="root/EnabledMethodDocs"/>publicboolEnabled(booltrue)
{
}
Aviolationofthisruleoccurswhentheincludetagismissingafileorpathattribute,orcontainsanimproperlyformattedfileorpathattribute.
![Page 221: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/221.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorcorrectthefileandpathattributes.
![Page 222: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/222.jpg)
TypeName InheritDocMustBeUsedWithInheritingClass
CheckId SA1648
Category DocumentationRules
![Page 223: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/223.jpg)
Cause<inheritdoc>hasbeenusedonanelementthatdoesntinheritfromabaseclassorimplementaninterface..
![Page 224: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/224.jpg)
RuleDescriptionVerifiesthatan'inheritdoc'tagisnotusedwhentheclassorinterfacedoesnotinheritfromabaseclassorinterface.
Aviolationofthisruleoccurswhentheelementhavingtheinheritdoctagdoesn'tinheritfromabasecaseorimplementaninterface.
![Page 225: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/225.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removethe<inheritdoc>taganddocumenttheelementappropriately.
![Page 226: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/226.jpg)
TypeName FileHeaderFileNameDocumentationMustMatchTypeName
CheckId SA1649
Category DocumentationRules
![Page 227: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/227.jpg)
CauseThefiletagwithinthefileheaderatthetopofaC#codefiledoesnotmatchthefirsttypedeclaredinthefile.ForgenericsthataredefinedasClass1<T>thenameofthefileneedstobeClass1{T}.csandthisshouldappearintheheaderalso.Partialclassesareignored.
![Page 228: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/228.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefiletagwithinthefileheaderatthetopofaC#filedoesnotcontainthenameofthefirsttypeinthefile.Forexample,consideraC#sourcefilenamedClass1.cs,withthefollowingheader:
//-----------------------------------------------------------------------
//<copyrightfile="ThisIsNotTheCorrectTypeName.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
publicclassClass1{
}
Aviolationofthisrulewouldoccur,sincethefiletagdoesnotcontainthecorrectnameofthefirsttypeinthefile.Theheadershouldbewrittenas:
//-----------------------------------------------------------------------
//<copyrightfile="Class1.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
publicclassClass1{
![Page 229: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/229.jpg)
}
Agenericclassshouldbewrittenas:
//-----------------------------------------------------------------------
//<copyrightfile="Class1{T}.cs"company="MyCompany">
//Customcompanycopyrighttag.
//</copyright>
//-----------------------------------------------------------------------
publicclassClass1<T>{
}
![Page 230: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/230.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addthenameofthefirsttypefromthefiletothefiletag.
![Page 231: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/231.jpg)
Ruleswhichenforcecodelayoutandlinespacing.
SA1500:CurlyBracketsForMultiLineStatementsMustNotShareLine
SA1501:StatementMustNotBeOnSingleLine
SA1502:ElementMustNotBeOnSingleLine
SA1503:CurlyBracketsMustNotBeOmitted
SA1504:AllAccessorMustBeMultiLineOrSingleLine
SA1505:OpeningCurlyBracketsMustNotBeFollowedByBlankLine
SA1506:ElementDocumentationHeadersMustNotBeFollowedByBlankLine
SA1507:CodeMustNotContainMultipleBlankLinesInARow
SA1508:ClosingCurlyBracketsMustNotBePrecededByBlankLine
SA1509:OpeningCurlyBracketsMustNotBePrecedededByBlankLine
SA1510:ChainedStatementBlocksMustNotBePrecededByBlankLine
SA1511:WhileDoFooterMustNotBePrecededByBlankLine
SA1512:SingleLineCommentsMustNotBeFollowedByBlankLine
SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine
SA1514:ElementDocumentationHeaderMustBePrecededByBlankLine
SA1515:SingleLineCommentMustBePrecededByBlankLine
SA1516:ElementsMustBeSeparatedByBlankLine
SA1517:CodeMustNotContainBlankLinesAtStartOfFile
SA1518:CodeMustNotContainBlankLinesAtEndOfFile
![Page 232: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/232.jpg)
TypeName CurlyBracketsForMultiLineStatementsMustNotShareLine
CheckId SA1500
Category LayoutRules
![Page 233: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/233.jpg)
CauseTheopeningorclosingcurlybracketwithinaC#statement,element,orexpressionisnotplacedonitsownline.
![Page 234: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/234.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheopeningorclosingcurlybracketwithinastatement,element,orexpressionisnotplacedonitsownline.Forexample:
publicobjectMethod()
{
lock(this){
returnthis.value;
}
}
WhenStyleCopchecksthiscode,aviolationofthisrulewilloccurbecausetheopeningcurlybracketofthelockstatementisplacedonthesamelineasthelockkeyword,ratherthanbeingplacedonitsownline,asfollows:
publicobjectMethod()
{
lock(this)
{
returnthis.value;
}
}
Aviolationwillalsooccuriftheclosingcurlybracketsharesalinewithothercode.Forexample:
publicobjectMethod()
![Page 235: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/235.jpg)
{
lock(this)
{
returnthis.value;}
}
![Page 236: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/236.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatboththeopeningandclosingcurlybracketsareplacedontheirownline,anddonotsharethelinewithanyothercode,otherthancomments.
![Page 237: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/237.jpg)
TypeName StatementMustNotBeOnASingleLine
CheckId SA1501
Category LayoutRules
![Page 238: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/238.jpg)
CauseAC#statementcontainingopeningandclosingcurlybracketsiswrittencompletelyonasingleline.
![Page 239: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/239.jpg)
RuleDescriptionAviolationofthisruleoccurswhenastatementthatiswrappedinopeningandclosingcurlybracketsiswrittenonasingleline.Forexample:
publicobjectMethod()
{
lock(this){returnthis.value;}
}
WhenStyleCopchecksthiscode,aviolationofthisrulewilloccurbecausetheentirelockstatementiswrittenononeline.Thestatementshouldbewrittenacrossmultiplelines,withtheopeningandclosingcurlybracketseachontheirownline,asfollows:
publicobjectMethod()
{
lock(this)
{
returnthis.value;
}
}
![Page 240: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/240.jpg)
HowtoFixViolationsTofixaviolationofthisrule,rewritethestatementsothatitexpandsacrossmultiplelines.
![Page 241: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/241.jpg)
TypeName ElementMustNotBeOnASingleLine
CheckId SA1502
Category LayoutRules
![Page 242: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/242.jpg)
CauseAC#elementcontainingopeningandclosingcurlybracketsiswrittencompletelyonasingleline.
![Page 243: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/243.jpg)
RuleDescriptionAviolationofthisruleoccurswhenanelementthatiswrappedinopeningandclosingcurlybracketsiswrittenonasingleline.Forexample:
publicobjectMethod(){returnnull;}
WhenStyleCopchecksthiscode,aviolationofthisrulewilloccurbecausetheentiremethodiswrittenononeline.Themethodshouldbewrittenacrossmultiplelines,withtheopeningandclosingcurlybracketseachontheirownline,asfollows:
publicobjectMethod()
{
returnnull;
}
Asanexceptiontothisrule,accessorswithinproperties,events,orindexersareallowedtobewrittenallonasingleline,aslongastheaccessorisshort.
![Page 244: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/244.jpg)
HowtoFixViolationsTofixaviolationofthisrule,rewritetheelementsothatitexpandsacrossmultiplelines.
![Page 245: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/245.jpg)
TypeName CurlyBracketsMustNotBeOmitted
CheckId SA1503
Category LayoutRules
![Page 246: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/246.jpg)
CauseTheopeningandclosingcurlybracketsforaC#statementhavebeenomitted.
![Page 247: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/247.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheopeningandclosingcurlybracketsforastatementhavebeenomitted.InC#,sometypesofstatementsmayoptionallyincludecurlybrackets.Examplesincludeif,while,andforstatements.Forexample,anif-statementmaybewrittenwithoutcurlybrackets:
if(true)
returnthis.value;
AlthoughthisislegalinC#,StyleCopalwaysrequiresthecurlybracketstobepresent,toincreasethereadabilityandmaintainabilityofthecode.
Whenthecurlybracketsareomitted,itispossibletointroduceanerrorinthecodebyinsertinganadditionalstatementbeneaththeif-statement.Forexample:
if(true)
this.value=2;
returnthis.value;
Glancingatthiscode,itappearsasifboththeassignmentstatementandthereturnstatementarechildrenoftheif-statement.Infact,thisisnottrue.Onlytheassignmentstatementisachildoftheif-statement,andthereturnstatementwillalwaysexecuteregardlessoftheoutcomeoftheif-statement.
StyleCopalwaysrequirestheopeningandclosingcurlybracketstobepresent,topreventthesekindsoferrors:
if(true)
{
this.value=2;
returnthis.value;
}
![Page 248: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/248.jpg)
![Page 249: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/249.jpg)
HowtoFixViolationsTofixaviolationofthisrule,wrapthebodyofthestatementincurlybrackets.
![Page 250: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/250.jpg)
TypeName AllAccessorsMustBeSingleLineOrMultiLine
CheckId SA1504
Category LayoutRules
![Page 251: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/251.jpg)
CauseWithinaC#property,indexerorevent,atleastoneofthechildaccessorsiswrittenonasingleline,andatleastoneofthechildaccessorsiswrittenacrossmultiplelines.
![Page 252: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/252.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheaccessorswithinaproperty,indexeroreventarenotconsistentlywrittenonasinglelineoronmultiplelines.Thisruleisintendedtoincreasethereadabilityofthecodebyrequiringalloftheaccessorswithinanelementtobeformattedinthesameway.
Forexample,thefollowingpropertywouldgenerateaviolationofthisrule,becauseoneaccessoriswrittenonasinglelinewhiletheotheraccessorsnapsmultiplelines.
publicboolEnabled
{
get{returnthis.enabled;}
set
{
this.enabled=value;
}
}
Theviolationcanbeavoidedbyplacingbothaccessorsonasingleline,orexpandingbothaccessorsacrossmultiplelines:
publicboolEnabled
{
get{returnthis.enabled;}
set{this.enabled=value;}
![Page 253: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/253.jpg)
}
publicboolEnabled
{
get
{
returnthis.enabled;
}
set
{
this.enabled=value;
}
}
![Page 254: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/254.jpg)
HowtoFixViolationsTofixaviolationofthisrule,writeeachaccessoronasinglelineiftheaccessorsareshort,orexpandbothaccessorsacrossmultiplelinesiftheaccessorsarelonger.
![Page 255: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/255.jpg)
TypeName OpeningCurlyBracketsMustNotBeFollowedByBlankLine
CheckId SA1505
Category LayoutRules
![Page 256: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/256.jpg)
CauseAnopeningcurlybracketwithinaC#element,statement,orexpressionisfollowedbyablankline.
![Page 257: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/257.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenanopeningcurlybracketisfollowedbyablankline.Forexample:
publicboolEnabled
{
get
{
returnthis.enabled;
}
}
Thecodeabovewouldgeneratetwoinstancesofthisviolation,sincetherearetwoplaceswhereopeningcurlybracketsarefollowedbyblanklines.
![Page 258: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/258.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklinefollowingtheopeningcurlybracket.
![Page 259: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/259.jpg)
TypeName ElementDocumentationHeadersMustNotBeFollowedByBlankLine
CheckId SA1506
Category LayoutRules
![Page 260: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/260.jpg)
CauseAnelementdocumentationheaderaboveaC#elementisfollowedbyablankline.
![Page 261: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/261.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhentheelementdocumentationheaderaboveanelementisfollowedbyablankline.Forexample:
///<summary>
///Getsavalueindicatingwhetherthecontrolisenabled.
///</summary>
publicboolEnabled
{
get{returnthis.enabled;}
}
Thecodeabovewouldgenerateaninstanceofthisviolation,sincethedocumentationheaderisfollowedbyablankline.
![Page 262: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/262.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklinefollowingthedocumentationheader.
![Page 263: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/263.jpg)
TypeName CodeMustNotContainMultipleBlankLinesInARow
CheckId SA1507
Category LayoutRules
![Page 264: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/264.jpg)
CauseTheC#codecontainsmultipleblanklinesinarow.
![Page 265: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/265.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenthecodecontainsmorethanoneblanklineinarow.Forexample:
publicboolEnabled
{
get
{
Console.WriteLine("Gettingtheenabledflag.");
returnthis.enabled;
}
}
Thecodeabovewouldgenerateaninstanceofthisviolation,sinceitcontainsblankmultiplelinesinarow.
![Page 266: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/266.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheextrablanklines.
![Page 267: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/267.jpg)
TypeName ClosingCurlyBracketsMustNotBePrecededByBlankLine
CheckId SA1508
Category LayoutRules
![Page 268: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/268.jpg)
CauseAclosingcurlybracketwithinaC#element,statement,orexpressionisprecededbyablankline.
![Page 269: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/269.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenaclosingcurlybracketisprecededbyablankline.Forexample:
publicboolEnabled
{
get
{
returnthis.enabled;
}
}
Thecodeabovewouldgeneratetwoinstancesofthisviolation,sincetherearetwoplaceswhereclosingcurlybracketsareprecededbyblanklines.
![Page 270: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/270.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklineprecedingtheclosingcurlybracket.
![Page 271: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/271.jpg)
TypeName OpeningCurlyBracketsMustNotBePrecededByBlankLine
CheckId SA1509
Category LayoutRules
![Page 272: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/272.jpg)
CauseAnopeningcurlybracketwithinaC#element,statement,orexpressionisprecededbyablankline.
![Page 273: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/273.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenanopeningcurlybracketisprecededbyablankline.Forexample:
publicboolEnabled
{
get
{
returnthis.enabled;
}
}
Thecodeabovewouldgeneratetwoinstancesofthisviolation,sincetherearetwoplaceswhereopeningcurlybracketsareprecededbyblanklines.
![Page 274: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/274.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklineprecedingtheopeningcurlybracket.
![Page 275: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/275.jpg)
TypeName ChainedStatementBlocksMustNotBePrecededByBlankLine
CheckId SA1510
Category LayoutRules
![Page 276: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/276.jpg)
CauseChainedC#statementsareseparatedbyablankline.
![Page 277: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/277.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
SometypesofC#statementscanonlybeusedwhenchainedtothebottomofanotherstatement.Examplesincludecatchandfinallystatements,whichmustalwaysbechainedtothebottomofatry-statement.Anotherexampleisanelse-statement,whichmustalwaysbechainedtothebottomofanif-statement,ortoanotherelse-statement.Thesetypesofchainedstatementsmustnotbeseparatedbyablankline.Forexample:
try
{
this.SomeMethod();
}
catch(Exceptionex)
{
Console.WriteLine(ex.ToString());
}
![Page 278: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/278.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removeanyblanklinesbetweenthechainedstatements.
![Page 279: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/279.jpg)
TypeName WhileDoFooterMustNotBePrecededByBlankLine
CheckId SA1511
Category LayoutRules
![Page 280: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/280.jpg)
CauseThewhilefooteratthebottomofado-whilestatementisseparatedfromthestatementbyablankline.
![Page 281: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/281.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenthewhilekeywordatthebottomofado-whilestatementisseparatedfromthemainpartofthestatementbyoneormoreblanklines.Forexample:
do
{
Console.WriteLine("Loopforever");
}
while(true);
![Page 282: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/282.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removeanyblanklinesbeforethewhilekeyword.
![Page 283: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/283.jpg)
TypeName SingleLineCommentsMustNotBeFollowedByBlankLine
CheckId SA1512
Category LayoutRules
![Page 284: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/284.jpg)
CauseAsingle-linecommentwithinC#codeisfollowedbyablankline.
![Page 285: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/285.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenasingle-linecommentisfollowedbyablankline.Forexample:
publicboolEnabled
{
get
{
//Returnthevalueofthe'enabled'field.
returnthis.enabled;
}
}
Thecodeabovewouldgenerateaninstanceofthisviolation,sincethesingle-linecommentisfollowedbyablankline.
Itisallowedtoplaceablanklineinbetweentwoblocksofsingle-linecomments.Forexample:
publicboolEnabled
{
get
{
![Page 286: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/286.jpg)
//Thisisasamplecommentwhichdoesn'treallysayanything.
//Thisisanotherpartofthecomment.
//Thereisablanklineabovethiscommentbutthatisok.
returnthis.enabled;
}
}
Ifthecommentisbeingusedtocommentoutalineofcode,placefourforwardslashesatthebeginningofthecomment,ratherthantwo.ThiswillcauseStyleCoptoignorethisviolation.Forexample:
publicboolEnabled
{
get
{
////returnfalse;
returnthis.enabled;
}
}
![Page 287: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/287.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklinefollowingthesingle-linecomment.
![Page 288: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/288.jpg)
TypeName ClosingCurlyBracketMustBeFollowedByBlankLine
CheckId SA1513
Category LayoutRules
![Page 289: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/289.jpg)
CauseAclosingcurlybracketwithinaC#element,statement,orexpressionisnotfollowedbyablankline.
![Page 290: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/290.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenaclosingcurlybracketisnotfollowedbyablankline.Forexample:
publicboolEnabled
{
get
{
returnthis.enabled;
}}
Thecodeabovewouldgenerateoneinstanceofthisviolation,sincethereisoneplacewhereaclosingcurlybracketisnotfollowedbyablankline.
![Page 291: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/291.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensureablanklinefollowsclosingcurlybrackets.
![Page 292: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/292.jpg)
TypeName ElementDocumentationHeadersMustBePrecededByBlankLine
CheckId SA1514
Category LayoutRules
![Page 293: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/293.jpg)
CauseAnelementdocumentationheaderaboveaC#elementisnotprecededbyablankline.
![Page 294: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/294.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhentheelementdocumentationheaderaboveanelementisnotprecededbyablankline.Forexample:
publicboolVisible
{
get{returnthis.visible;}
}
///<summary>
///Getsavalueindicatingwhetherthecontrolisenabled.
///</summary>
publicboolEnabled
{
get{returnthis.enabled;}
}
Thecodeabovewouldgenerateaninstanceofthisviolation,sincethedocumentationheaderisnotprecededbyablankline.
Anexceptiontothisruleoccurswhenthedocumentationheaderisthefirstitemwithinitsscope.Inthiscase,theheadershouldnotbeprecededbyablankline.Forexample:
publicclassClass1
![Page 295: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/295.jpg)
{
///<summary>
///Getsavalueindicatingwhetherthecontrolisenabled.
///</summary>
publicboolEnabled
{
get{returnthis.enabled;}
}
}
Inthecodeabove,theheaderisthefirstitemwithinitsscope,andthusitshouldnotbeprecededbyablankline.
![Page 296: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/296.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addablanklineabovethedocumentationheader.
![Page 297: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/297.jpg)
TypeName SingleLineCommentsMustBePrecededByBlankLine
CheckId SA1515
Category LayoutRules
![Page 298: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/298.jpg)
CauseAsingle-linecommentwithinC#codeisnotprecededbyablankline.
![Page 299: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/299.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhenasingle-linecommentisnotprecededbyablankline.Forexample:
publicboolEnabled
{
get
{
Console.WriteLine("Gettingtheenabledflag.");
//Returnthevalueofthe'enabled'field.
returnthis.enabled;
}
}
Thecodeabovewouldgenerateaninstanceofthisviolation,sincethesingle-linecommentisnotprecededbyablankline.
Anexceptiontothisruleoccurswhenthesingle-linecommentisthefirstitemwithinitsscope.Inthiscase,thecommentshouldnotbeprecededbyablankline.Forexample:
publicboolEnabled
{
get
![Page 300: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/300.jpg)
{
//Returnthevalueofthe'enabled'field.
returnthis.enabled;
}
}
Inthecodeabove,thecommentisthefirstitemwithinitsscope,andthusitshouldnotbeprecededbyablankline.
Ifthecommentisbeingusedtocommentoutalineofcode,beginthecommentwithfourforwardslashesratherthantwo.ThiswillcauseStyleCoptoignorethisviolation.Forexample:
publicboolEnabled
{
get
{
Console.WriteLine("Gettingtheenabledflag.");
////returnfalse;returnthis.enabled;
}
}
![Page 301: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/301.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addablanklineabovethecomment.
![Page 302: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/302.jpg)
TypeName ElementsMustBeSeparatedByBlankLine
CheckId SA1516
Category LayoutRules
![Page 303: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/303.jpg)
CauseAdjacentC#elementsarenotseparatedbyablankline.
![Page 304: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/304.jpg)
RuleDescriptionToimprovethereadabilityofthecode,StyleCoprequiresblanklinesincertainsituations,andprohibitsblanklinesinothersituations.Thisresultsinaconsistentvisualpatternacrossthecode,whichcanimproverecognitionandreadabilityofunfamiliarcode.
Aviolationofthisruleoccurswhentwoadjacentelementarenotseparatedbyablankline.Forexample:
publicvoidMethod1()
{
}
publicboolProperty
{
get{returntrue;}
}
Intheexampleabove,themethodandpropertyarenotseparatedbyablankline,soaviolationofthisrulewouldoccur.
publiceventEventHandlerSomeEvent{add{//addeventsubscriberhere}
remove
![Page 305: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/305.jpg)
{//removeeventsubscriberhere}
}
Intheexampleabove,theaddandremoveoftheeventneedtobeseparatedbyablanklinebecausetheaddismultiline.
![Page 306: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/306.jpg)
HowtoFixViolations>HowtoFixViolationsTofixaviolationofthisrule,addablanklinebetweentheadjacentelements.
![Page 307: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/307.jpg)
TypeName CodeMustNotContainBlankLinesAtStartOfFile
CheckId SA1517
Category LayoutRules
![Page 308: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/308.jpg)
CauseThecodefilehasblanklinesatthestart.
![Page 309: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/309.jpg)
RuleDescriptionToimprovethelayoutofthecode,StyleCoprequiresnoblanklinesatthestartoffiles.
Aviolationofthisruleoccurswhenoneormoreblanklinesareatthestartofthefile.
![Page 310: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/310.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklinesfromthestartofthefile.
![Page 311: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/311.jpg)
TypeName CodeMustNotContainBlankLinesAtEndOfFile
CheckId SA1518
Category LayoutRules
![Page 312: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/312.jpg)
CauseThecodefilehasblanklinesattheend.
![Page 313: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/313.jpg)
RuleDescriptionToimprovethelayoutofthecode,StyleCoprequiresnoblanklinesattheendoffiles.
Aviolationofthisruleoccurswhenoneormoreblanklinesareattheendofthefile.
![Page 314: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/314.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheblanklinesfromtheendofthefile.
![Page 315: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/315.jpg)
Ruleswhichimprovecodemaintainability.
SA1119:StatementMustNotUseUnnecessaryParenthesis
SA1400:AccessModifierMustBeDeclared
SA1401:FieldsMustBePrivate
SA1402:FileMayOnlyContainASingleClass
SA1403:FileMayOnlyContainASingleNamespace
SA1404:CodeAnalysisSuppressionMustHaveJustification
SA1405:DebugAssertMustProvideMessageText
SA1406:DebugFailMustProvideMessageText
SA1407:ArithmeticExpressionsMustDeclarePrecedence
SA1408:ConditionalExpressionsMustDeclarePrecendence
SA1409:RemoveUnnecessaryCode
SA1410:RemoveDelegateParenthesisWhenPossible
SA1411:AttributeConstructorMustNotUseUnnecessaryParenthesis
![Page 316: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/316.jpg)
TypeName StatementMustNotUseUnnecessaryParenthesis
CheckId SA1119
Category MaintainabilityRules
![Page 317: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/317.jpg)
CauseAC#statementcontainsparenthesiswhichareunnecessaryandshouldberemoved.
![Page 318: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/318.jpg)
RuleDescriptionItispossibleinC#toinsertparenthesisaroundvirtuallyanytypeofexpression,statement,orclause,andinmanysituationsuseofparenthesiscangreatlyimprovethereadabilityofthecode.However,excessiveuseofparenthesiscanhavetheoppositeeffect,makingitmoredifficulttoreadandmaintainthecode.
Aviolationofthisruleoccurswhenparenthesisareusedinsituationswheretheyprovidenopracticalvalue.Typically,thishappensanytimetheparenthesissurroundanexpressionwhichdoesnotstrictlyrequiretheuseofparenthesis,andtheparenthesisexpressionislocatedattherootofastatement.Forexample,thefollowinglinesofcodeallcontainunnecessaryparenthesiswhichwillresultinviolationsofthisrule:
intx=(5+b);
stringy=(this.Method()).ToString();
return(x.Value);
Ineachofthesestatements,theextraparenthesiscanberemovedwithoutsacrificingthereadabilityofthecode:
intx=5+b;
stringy=this.Method().ToString();
returnx.Value;
![Page 319: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/319.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheunnecessaryparenthesis.
![Page 320: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/320.jpg)
TypeName AccessModifierMustBeDeclared
CheckId SA1400
Category MaintainabilityRules
![Page 321: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/321.jpg)
CauseTheaccessmodifierforaC#elementhasnotbeenexplicitlydefined.
![Page 322: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/322.jpg)
RuleDescriptionC#allowselementstobedefinedwithoutanaccessmodifier.Dependinguponthetypeofelement,C#willautomaticallyassignanaccessleveltotheelementinthiscase.
Thisrulerequiresanaccessmodifiertobeexplicitlydefinedforeveryelement.Thisremovestheneedforthereadertomakeassumptionsaboutthecode,improvingthereadabilityofthecode.
![Page 323: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/323.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addanaccessmodifiertothedeclarationoftheelement.
![Page 324: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/324.jpg)
TypeName FieldsMustBePrivate
CheckId SA1401
Category MaintainabilityRules
![Page 325: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/325.jpg)
CauseAfieldwithinaC#classhasanaccessmodifierotherthanprivate.
![Page 326: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/326.jpg)
RuleDescriptionAviolationofthisruleoccurswheneverafieldinaclassisgivennon-privateaccess.Formaintainabilityreasons,propertiesshouldalwaysbeusedasthemechanismforexposingfieldsoutsideofaclass,andfieldsshouldalwaysbedeclaredwithprivateaccess.Thisallowstheinternalimplementationofthepropertytochangeovertimewithoutchangingtheinterfaceoftheclass.
FieldslocatedwithinC#structsareallowedtohaveanyaccesslevel.
![Page 327: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/327.jpg)
HowtoFixViolationsTofixaviolationofthisrule,makethefieldprivateandaddapropertytoexposethefieldoutsideoftheclass.
![Page 328: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/328.jpg)
TypeName FileMayOnlyContainASingleClass
CheckId SA1402
Category MaintainabilityRules
![Page 329: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/329.jpg)
CauseAC#codefilecontainsmorethanoneuniqueclass.
![Page 330: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/330.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaC#filecontainsmorethanoneclass.Toincreaselong-termmaintainabilityofthecode-base,eachclassshouldbeplacedinitsownfile,andfilenamesshouldreflectthenameoftheclasswithinthefile.
Itispossibletoplaceothersupportingelementswithinthesamefileastheclass,suchasdelegates,enums,etc.,iftheyarerelatedtotheclass.
Itisalsopossibletoplacemultiplepartsofthesamepartialclasswithinthesamefile.
![Page 331: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/331.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,moveeachclassintoitsownfile.
![Page 332: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/332.jpg)
TypeName FileMayOnlyContainASingleNamespace
CheckId SA1403
Category MaintainabilityRules
![Page 333: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/333.jpg)
CauseAC#codefilecontainsmorethanonenamespace.
![Page 334: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/334.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaC#filecontainsmorethanonenamespace.Toincreaselong-termmaintainabilityofthecode-base,eachfileshouldcontainatmostonenamespace.
![Page 335: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/335.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthefileonlycontainsasinglenamespace.
![Page 336: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/336.jpg)
TypeName CodeAnalysisSuppressionMustHaveJustification
CheckId SA1404
Category MaintainabilityRules
![Page 337: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/337.jpg)
CauseACodeAnalysisSuppressMessageattributedoesnotincludeajustification.
![Page 338: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/338.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainsaCodeAnalysisSuppressMessageattribute,butajustificationforthesuppressionhasnotbeenprovidedwithintheattribute.WheneveraCodeAnalysisruleissuppressed,ajustificationshouldbeprovided.Thiscanincreasethelong-termmaintainabilityofthecode.
[SuppressMessage("Microsoft.Performance","CA1804:RemoveUnusedLocals",Justification="Usedduringunittesting")]
publicboolEnable(){
}
![Page 339: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/339.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,addaJustificationtagandjustificationtexttotheSuppressMessageattributedescribingthereasonforthesuppression.
![Page 340: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/340.jpg)
TypeName DebugAssertMustProvideMessageText
CheckId SA1405
Category MaintainabilityRules
![Page 341: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/341.jpg)
CauseAcalltoDebug.AssertinC#codedoesnotincludeadescriptivemessage.
![Page 342: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/342.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainsacalltoDebug.Assertwhichdoesnotprovideadescriptionfortheend-user.Forexample,thefollowingassertincludesadescriptionmessage:
Debug.Assert(value!=true,"Thevaluemustalwaysbetrue.");
![Page 343: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/343.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addadescriptivemessagetotheassertwhichwillappeartotheenduserwhentheassertisfired.
![Page 344: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/344.jpg)
TypeName DebugFailMustProvideMessageText
CheckId SA1406
Category MaintainabilityRules
![Page 345: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/345.jpg)
CauseAcalltoDebug.FailinC#codedoesnotincludeadescriptivemessage.
![Page 346: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/346.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainsacalltoDebug.Failwhichdoesnotprovideadescriptionfortheend-user.Forexample,thefollowingcallincludesadescriptionmessage:
Debug.Fail("Thecodeshouldneverreachthispoint.");
![Page 347: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/347.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,addadescriptivemessagetotheDebug.Failcallwhichwillappeartotheenduserwhentheassertisfired.
![Page 348: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/348.jpg)
TypeName ArithmeticExpressionsMustDeclarePrecedence
CheckId SA1407
Category MaintainabilityRules
![Page 349: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/349.jpg)
CauseAC#statementcontainsacomplexarithmeticexpressionwhichomitsparenthesisaroundoperators.
![Page 350: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/350.jpg)
RuleDescriptionC#maintainsahierarchyofprecedenceforarithmeticoperators.ItispossibleinC#tostringmultiplearithmeticoperationstogetherinonestatementwithoutwrappinganyoftheoperationsinparenthesis,inwhichcasethecompilerwillautomaticallysettheorderandprecedenceoftheoperationsbasedonthesepre-establishedrules.Forexample:
intx=5+y*b/6%z-2;
Althoughthiscodeislegal,itisnothighlyreadableormaintainable.Inordertoachievefullunderstandingofthiscode,thedevelopermustknowandunderstandthebasicoperatorprecedencerulesinC#.
Thisruleisintendedtoincreasethereadabilityandmaintainabilityofthistypeofcode,andtoreducetheriskofintroducingbugslater,byforcingthedevelopertoinsertparenthesistoexplicitlydeclaretheoperatorprecedence.Theexamplebelowshowsmultiplearithmeticoperationssurroundedbyparenthesis:
intx=5+(y*((b/6)%z))-2;
Insertingparenthesismakesthecodemoreobviousandeasytounderstand,andremovestheneedforthereadertomakeassumptionsaboutthecode.
![Page 351: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/351.jpg)
HowtoFixViolationsTofixaviolationofthisrule,insertparenthesiswithinthearithmeticexpressiontodeclaretheprecedenceoftheoperations.
![Page 352: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/352.jpg)
TypeName ConditionalExpressionsMustDeclarePrecedence
CheckId SA1408
Category MaintainabilityRules
![Page 353: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/353.jpg)
CauseAC#statementcontainsacomplexconditionalexpressionwhichomitsparenthesisaroundoperators.
![Page 354: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/354.jpg)
RuleDescriptionC#maintainsahierarchyofprecedenceforconditionaloperators.ItispossibleinC#tostringmultipleconditionaloperationstogetherinonestatementwithoutwrappinganyoftheoperationsinparenthesis,inwhichcasethecompilerwillautomaticallysettheorderandprecedenceoftheoperationsbasedonthesepre-establishedrules.Forexample:
if(x||y&&z&&a||b)
{
}
Althoughthiscodeislegal,itisnothighlyreadableormaintainable.Inordertoachievefullunderstandingofthiscode,thedevelopermustknowandunderstandthebasicoperatorprecedencerulesinC#.
Thisruleisintendedtoincreasethereadabilityandmaintainabilityofthistypeofcode,andtoreducetheriskofintroducingbugslater,byforcingthedevelopertoinsertparenthesistoexplicitlydeclaretheoperatorprecedence.Forexample,adevelopercouldwritethiscodeas:
if((x||y)&&z&&(a||b))
{
}
or
if(x||(y&&z&&a)||b)
{
}
Insertingparenthesismakesthecodemoreobviousandeasytounderstand,andremovestheneedforthereadertomakeassumptionsaboutthecode.
![Page 355: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/355.jpg)
HowtoFixViolationsInsertparenthesiswithintheconditionalexpressiontodeclaretheprecedenceoftheoperations.
![Page 356: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/356.jpg)
TypeName RemoveUnnecessaryCode
CheckId SA1409
Category MaintainabilityRules
![Page 357: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/357.jpg)
CauseAC#filecontainscodewhichisunnecessaryandcanberemovedwithoutchangingtheoveralllogicofthecode.
![Page 358: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/358.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthefilecontainscodewhichcanberemovedwithoutchangingtheoveralllogicofthecode.
Forexample,thefollowingtry-catchstatementcouldberemovedcompletelysincethetryandcatchblocksarebothempty.
try
{
}
catch(Exceptionex)
{
}
Thetry-finallystatementbelowdoescontaincodewithinthetryblock,butitdoesnotcontainanycatchblocks,andthefinallyblockisempty.Thus,thetry-finallyisnotperforminganyusefulfunctionandcanberemoved.
try
{
this.Method();
}
finally
{
![Page 359: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/359.jpg)
}
Asafinalexample,theunsafestatementbelowisempty,andthusprovidesnovalue.
unsafe
{
}
![Page 360: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/360.jpg)
HowtoFixViolationsThefixaviolationofthisrule,removetheunnecessarycode,orfillinthecodewithadditionalstatements.
![Page 361: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/361.jpg)
TypeName RemoveDelegateParenthesisWhenPossible
CheckId SA1410
Category MaintainabilityRules
![Page 362: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/362.jpg)
CauseAcalltoaC#anonymousmethoddoesnotcontainanymethodparameters,yetthestatementstillincludesparenthesis.
![Page 363: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/363.jpg)
RuleDescriptionWhenananonymousmethoddoesnotcontainanymethodparameters,theparenthesisaroundtheparametersareoptional.
Aviolationofthisruleoccurswhentheparenthesisarepresentonananonymousmethodcallwhichtakesnomethodparameters.Forexample:
this.Method(delegate(){return2;});
Theparenthesisareunnecessaryandshouldberemoved:
this.Method(delegate{return2;});
![Page 364: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/364.jpg)
HowtoFixViolationsRemovetheunnecessaryparenthesisafterthedelegatekeyword.
![Page 365: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/365.jpg)
TypeName AttributeConstructorMustNotUseUnnecessaryParenthesis
CheckId SA1411
Category MaintainabilityRules
![Page 366: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/366.jpg)
CauseTODO.
![Page 367: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/367.jpg)
RuleDescriptionTODO
Aviolationofthisruleoccurswhenunneccsaryparenthesishavebeenusedinanattributeconstructor.Forexample:
[Serializable()]Theparenthesisareunnecessaryandshouldberemoved:
[Serializable]
![Page 368: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/368.jpg)
HowtoFixViolationsRemovetheunnecessaryparenthesis.
![Page 369: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/369.jpg)
Ruleswhichenforcenamingrequirementsformembers,types,andvariables.
SA1300:ElementMustBeginWithUpperCaseLetter
SA1301:ElementMustBeginWithLowerCaseLetter
SA1302:InterfaceNamesMustBeginWithI
SA1303:ConstFieldNamesMustBeginWithUpperCaseLetter
SA1304:NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter
SA1305:FieldNamesMustNotUseHungarianNotation
SA1306:FieldNamesMustBeginWithLowerCaseLetter
SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter
SA1308:VariableNamesMustNotBePrefixed
SA1309:FieldNamesMustNotBeginWithUnderscore
SA1310:FieldNamesMustNotContainUnderscore
![Page 370: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/370.jpg)
TypeName ElementMustBeginWithUpperCaseLetter
CheckId SA1300
Category NamingRules
![Page 371: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/371.jpg)
CauseThenameofaC#elementdoesnotbeginwithanupper-caseletter.
![Page 372: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/372.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthenamesofcertaintypesofelementsdonotbeginwithanupper-caseletter.Thefollowingtypesofelementsshoulduseanupper-caseletterasthefirstletteroftheelementname:namespaces,classes,enums,structs,delegates,events,methods,andproperties.
Inaddition,anyfieldwhichispublic,internal,ormarkedwiththeconstattributeshouldbeginwithanupper-caseletter.Non-privatereadonlyfieldsmustalsobenamedusinganupper-caseletter.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstobeginwithalower-caseletter,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 373: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/373.jpg)
HowtoFixViolationsTofixaviolationofthisrule,changethenameoftheelementsothatitbeginswithanupper-caseletter,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 374: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/374.jpg)
TypeName ElementMustBeginWithLowerCaseLetter
CheckId SA1301
Category NamingRules
![Page 375: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/375.jpg)
CauseTherearecurrentlynosituationsinwhichthisrulewillfire.
![Page 376: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/376.jpg)
TypeName InterfaceNamesMustBeginWithI
CheckId SA1302
Category NamingRules
![Page 377: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/377.jpg)
CauseThenameofaC#interfacedoesnotbeginwiththecapitalletterI.
![Page 378: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/378.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthenameofaninterfacedoesnotbeginwiththecapitalletterI.InterfacenamesshouldalwaysbeginwithI.Forexample,ICustomer.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthuscannotbeginwiththeletterI,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 379: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/379.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addthecapitalletterItothefrontoftheinterfacename,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 380: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/380.jpg)
TypeName ConstFieldNamesMustBeginWithUpperCaseLetter
CheckId SA1303
Category NamingRules
![Page 381: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/381.jpg)
CauseThenameofaconstantC#fieldmustbeginwithanupper-caseletter.
![Page 382: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/382.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthenameofafieldmarkedwiththeconstattributedoesnotbeginwithanupper-caseletter.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstobeginwithalower-caseletter,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 383: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/383.jpg)
HowtoFixViolationsTofixaviolationofthisrule,changethenameoftheconstantfieldsothatitbeginswithanupper-caseletter,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 384: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/384.jpg)
TypeName NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter
CheckId SA1304
Category NamingRules
![Page 385: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/385.jpg)
CauseThenameofanon-privatereadonlyC#fieldmustbeingwithanupper-caseletter.
![Page 386: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/386.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthenameofareadonlyfieldwhichisnotprivatedoesnotbeginwithanupper-caseletter.Non-privatereadonlyfieldsmustalwaysstartwithanupper-caseletter.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstobeginwithalower-caseletter,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 387: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/387.jpg)
HowtoFixViolationsTofixaviolationofthisrule,changethenameofthereadonlyfieldsothatitbeginswithanupper-caseletter,makethefieldprivate,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 388: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/388.jpg)
TypeName FieldNamesMustNotUseHungarianNotation
CheckId SA1305
Category NamingRules
![Page 389: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/389.jpg)
CauseThenameofafieldorvariableinC#usesHungariannotation.
![Page 390: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/390.jpg)
RuleDescriptionAviolationofthisruleoccurswhenHungariannotationisusedinthenamingoffieldsandvariables.TheuseofHungariannotationhasbecomewidespreadinC++code,butthetrendinC#istouselonger,moredescriptivenamesforvariables,whicharenotbasedonthetypeofthevariablebutwhichinsteaddescribewhatthevariableisusedfor.
Inaddition,moderncodeeditorssuchasVisualStudiomakeiteasytoidentifytypeinformationforavariableorfield,typicallybyhoveringthemousecursoroverthevariablename.ThisreducestheneedforHungariannotation.
StyleCopassumesthatanyvariablenamethatbeginswithoneortwolower-caselettersfollowedbyanupper-caseletterismakinguseofHungariannotation,andwillflagaviolationofthisruleineachcase.Itispossibletodeclarecertainprefixesaslegal,inwhichcasetheywillbeignored.Forexample,avariablenamedonExecutewillappeartoStyleCoptobeusingHungariannotation,wheninrealityitisnot.Thus,theonprefixshouldbeflaggedasanallowedprefix.
Toconfigurethelistofallowedprefixes,bringuptheStyleCopsettingsforaproject,andnavigatetotheHungariantab,asshownbelow:
AddingaoneortwoletterprefixtothislistwillcauseStyleCoptoignore
![Page 391: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/391.jpg)
variablesorfieldswhichbeginwiththisprefix.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstouseHungariannotation,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 392: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/392.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheHungariannotationfromthefieldorvariablename,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 393: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/393.jpg)
TypeName FieldNamesMustBeginWithLowerCaseLetter
CheckId SA1306
Category NamingRules
![Page 394: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/394.jpg)
CauseThenameofafieldorvariableinC#doesnotbeginwithalower-caseletter.
![Page 395: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/395.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthenameofafieldorvariablebeginswithanupper-caseletter.Constantsmustalwaysstartwithanuppercaseletter,whilstreadonlyfieldsmaystartwitheitheranuppercaseoralowercaseletter.Also,publicorinternalfieldsmustalwaysstartwithanuppercaseletter.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstobeginwithanupper-caseletter,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 396: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/396.jpg)
HowtoFixViolationsTofixaviolationofthisrule,changethenameofthefieldorvariablesothatitbeginswithalower-caseletter,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 397: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/397.jpg)
TypeName AccessibleFieldsMustBeginWithUpperCaseLetter
CheckId SA1307
Category NamingRules
![Page 398: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/398.jpg)
CauseThenameofapublicorinternalfieldinC#doesnotbeginwithanupper-caseletter.
![Page 399: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/399.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthenameofapublicorinternalfieldbeginswithalower-caseletter.Publicorinternalfieldsmustbeingwithanupper-caseletter.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstostartwithalower-caseletter,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 400: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/400.jpg)
HowtoFixViolationsTofixaviolationofthisrule,changethenameofthefieldsothatitbeginswithanupper-caseletter,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 401: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/401.jpg)
TypeName VariableNamesMustNotBePrefixed
CheckId SA1308
Category NamingRules
![Page 402: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/402.jpg)
CauseAfieldnameinC#isprefixedwithm_ors_.
![Page 403: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/403.jpg)
RuleDescriptionAviolationofthisruleoccurswhenafieldnameisprefixedbym_ors_.
Bydefault,StyleCopdisallowstheuseofunderscores,m_,etc.,tomarklocalclassfields,infavorofthe‘this.’prefix.Theadvantageofusing‘this.’isthatitappliesequallytoallelementtypesincludingmethods,properties,etc.,andnotjustfields,makingallcallstoclassmembersinstantlyrecognizable,regardlessofwhicheditorisbeingusedtoviewthecode.Anotheradvantageisthatitcreatesaquick,recognizabledifferentiationbetweeninstancemembersandstaticmembers,whichwillnotbeprefixed.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstobeginwiththeprefix,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 404: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/404.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheprefixfromthebeginningofthefieldname,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 405: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/405.jpg)
TypeName FieldNamesMustNotBeginWithUnderscore
CheckId SA1309
Category NamingRules
![Page 406: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/406.jpg)
CauseAfieldnameinC#beginswithanunderscore.
![Page 407: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/407.jpg)
RuleDescriptionAviolationofthisruleoccurswhenafieldnamebeginswithanunderscore.
Bydefault,StyleCopdisallowstheuseofunderscores,m_,etc.,tomarklocalclassfields,infavorofthe‘this.’prefix.Theadvantageofusing‘this.’isthatitappliesequallytoallelementtypesincludingmethods,properties,etc.,andnotjustfields,makingallcallstoclassmembersinstantlyrecognizable,regardlessofwhicheditorisbeingusedtoviewthecode.Anotheradvantageisthatitcreatesaquick,recognizabledifferentiationbetweeninstancemembersandstaticmembers,whichwillnotbeprefixed.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstobeginwithanunderscore,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 408: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/408.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheunderscorefromthebeginningofthefieldname,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 409: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/409.jpg)
TypeName FieldNamesMustNotContainUnderscore
CheckId SA1310
Category NamingRules
![Page 410: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/410.jpg)
CauseAfieldnameinC#containsanunderscore.
![Page 411: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/411.jpg)
RuleDescriptionAviolationofthisruleoccurswhenafieldnamecontainsanunderscore.Fieldsandvariablesshouldbenamedusingdescriptive,readablewordingwhichdescribesthefunctionofthefieldorvariable.Typically,thesenameswillbewrittenusingcamelcase,andshouldnotuseunderscores.Forexample,usecustomerPostCoderatherthancustomer_post_code.
IfthefieldorvariablenameisintendedtomatchthenameofanitemassociatedwithWin32orCOM,andthusneedstoincludeunderscores,placethefieldorvariablewithinaspecialNativeMethodsclass.ANativeMethodsclassisanyclasswhichcontainsanameendinginNativeMethods,andisintendedasaplaceholderforWin32orCOMwrappers.StyleCopwillignorethisviolationiftheitemisplacedwithinaNativeMethodsclass.
![Page 412: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/412.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheunderscorefromthenameofthefield,orplacetheitemwithinaNativeMethodsclassifappropriate.
![Page 413: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/413.jpg)
Ruleswhichenforceastandardorderingschemeforcodecontents.
SA1200:UsingDirectivesMustBePlacedWithinNamespace
SA1201:ElementsMustAppearInTheCorrectOrder
SA1202:ElementsMustBeOrderedByAccess
SA1203:ConstantsMustAppearBeforeFields
SA1204:StaticElementsMustAppearBeforeInstanceElements
SA1205:PartialElementsMustDeclareAccess
SA1206:DeclarationKeywordsMustFollowOrder
SA1207:ProtectedMustComeBeforeInternal
SA1208:SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives
SA1209:UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives
SA1210:UsingDirectivesMustBeOrderedAlphabeticallyByNamespace
SA1211:UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName
SA1212:PropertyAccessorsMustFollowOrder
SA1213:EventAccessorsMustFollowOrder
![Page 414: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/414.jpg)
TypeName UsingDirectivesMustBePlacedWithinNamespace
CheckId SA1200
Category OrderingRules
![Page 415: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/415.jpg)
CauseAC#usingdirectiveisplacedoutsideofanamespaceelement.
![Page 416: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/416.jpg)
RuleDescriptionAviolationofthisruleoccurswhenausingdirectiveorausing-aliasdirectiveisplacedoutsideofanamespaceelement,unlessthefiledoesnotcontainanynamespaceelements.
Forexample,thefollowingcodewouldresultintwoviolationsofthisrule.
usingSystem;
usingGuid=System.Guid;
namespaceMicrosoft.Sample
{
publicclassProgram
{
}
}
Thefollowingcode,however,wouldnotresultinanyviolationsofthisrule:
namespaceMicrosoft.Sample
{
usingSystem;
usingGuid=System.Guid;
publicclassProgram
![Page 417: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/417.jpg)
{
}
}
Therearesubtledifferencesbetweenplacingusingdirectiveswithinanamespaceelement,ratherthanoutsideofthenamespace,including:
1.Placingusing-aliasdirectiveswithinthenamespaceeliminatescompilerconfusionbetweenconflictingtypes.
2.Whenmultiplenamespacesaredefinedwithinasinglefile,placingusingdirectiveswithinthenamespaceelementsscopesreferencesandaliases.
1.EliminatingTypeConfusion
Considerthefollowingcode,whichcontainsausing-aliasdirectivedefinedoutsideofthenamespaceelement.ThecodecreatesanewclasscalledGuid,andalsodefinesausing-aliasdirectivetomapthenameGuidtothetypeSystem.Guid.Finally,thecodecreatesaninstanceofthetypeGuid:
usingGuid=System.Guid;
namespaceMicrosoft.Sample
{
publicclassGuid
{
publicGuid(strings)
{
}
}
![Page 418: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/418.jpg)
publicclassProgram
{
publicstaticvoidMain(string[]args)
{
Guidg=newGuid("hello");
}
}
}
Thiscodewillcompilecleanly,withoutanycompilererrors.However,itisunclearwhichversionoftheGuidtypeisbeingallocated.Iftheusingdirectiveismovedinsideofthenamespace,asshownbelow,acompilererrorwilloccur:
namespaceMicrosoft.Sample
{
usingGuid=System.Guid;
publicclassGuid
{
publicGuid(strings)
{
![Page 419: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/419.jpg)
}
}
publicclassProgram
{
publicstaticvoidMain(string[]args)
{
Guidg=newGuid("hello");
}
}
}
Thecodefailsonthefollowingcompilererror,foundonthelinecontainingGuidg=newGuid("hello");
CS0576:Namespace'Microsoft.Sample'containsadefinitionconflictingwithalias'Guid'
ThecodecreatesanaliastotheSystem.GuidtypecalledGuid,andalsocreatesitsowntypecalledGuidwithamatchingconstructorinterface.Later,thecodecreatesaninstanceofthetypeGuid.Tocreatethisinstance,thecompilermustchoosebetweenthetwodifferentdefinitionsofGuid.Whentheusing-aliasdirectiveisplacedoutsideofthenamespaceelement,thecompilerwillchoosethelocaldefinitionofGuiddefinedwithinthelocalnamespace,andcompletelyignoretheusing-aliasdirectivedefinedoutsideofthenamespace.This,unfortunately,isnotobviouswhenreadingthecode.
![Page 420: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/420.jpg)
Whentheusing-aliasdirectiveispositionedwithinthenamespace,however,thecompilerhastochoosebetweentwodifferent,conflictingGuidtypesbothdefinedwithinthesamenamespace.Bothofthesetypesprovideamatchingconstructor.Thecompilerisunabletomakeadecision,soitflagsthecompilererror.
Placingtheusing-aliasdirectiveoutsideofthenamespaceisabadpracticebecauseitcanleadtoconfusioninsituationssuchasthis,whereitisnotobviouswhichversionofthetypeisactuallybeingused.Thiscanpotentiallyleadtoabugwhichmightbedifficulttodiagnose.
Placingusing-aliasdirectiveswithinthenamespaceelementeliminatesthisasasourceofbugs.
2.MultipleNamespaces
Placingmultiplenamespaceelementswithinasinglefileisgenerallyabadidea,butifandwhenthisisdone,itisagoodideatoplaceallusingdirectiveswithineachofthenamespaceelements,ratherthangloballyatthetopofthefile.Thiswillscopethenamespacestightly,andwillalsohelptoavoidthekindofbehaviordescribedabove.
Itisimportanttonotethatwhencodehasbeenwrittenwithusingdirectivesplacedoutsideofthenamespace,careshouldbetakenwhenmovingthesedirectiveswithinthenamespace,toensurethatthisisnotchangingthesemanticsofthecode.Asexplainedabove,placingusing-aliasdirectiveswithinthenamespaceelementallowsthecompilertochoosebetweenconflictingtypesinwaysthatwillnothappenwhenthedirectivesareplacedoutsideofthenamespace.
![Page 421: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/421.jpg)
HowtoFixViolationsTofixaviolationofthisrule,moveallusingdirectivesandusing-aliasdirectiveswithinthenamespaceelement.
![Page 422: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/422.jpg)
TypeName ElementsMustAppearInTheCorrectOrder
CheckId SA1201
Category OrderingRules
![Page 423: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/423.jpg)
CauseAnelementwithinaC#codefileisoutoforderinrelationtotheotherelementsinthecode.
![Page 424: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/424.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodeelementswithinafiledonotfollowastandardorderingscheme.
Tocomplywiththisrule,elementsatthefilerootlevelorwithinanamespacemustbepositionedinthefollowingorder:
ExternAliasDirectives
UsingDirectives
Namespaces
Delegates
Enums
Interfaces
Structs
Classes
Withinaclass,struct,orinterface,elementsmustbepositionedinthefollowingorder:
Fields
Constructors
Finalizers(Destructors)
Delegates
Events
Enums
Interfaces
Properties
Indexers
Methods
Structs
Classes
![Page 425: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/425.jpg)
Complyingwithastandardorderingschemebasedonelementtypecanincreasethereadabilityandmaintainabilityofthefileandencouragecodereuse.
Whenimplementinganinterface,itissometimesdesirabletogroupallmembersoftheinterfacenexttooneanother.Thiswillsometimesrequireviolatingthisrule,iftheinterfacecontainselementsofdifferenttypes.Thisproblemcanbesolvedthroughtheuseofpartialclasses.
1.Addthepartialattributetotheclass,iftheclassisnotalreadypartial.
2.Addasecondpartialclasswiththesamename.Itispossibletoplacethisinthesamefile,justbelowtheoriginalclass,orwithinasecondfile.
3.Movetheinterfaceinheritanceandallmembersoftheinterfaceimplementationtothesecondpartoftheclass.
Forexample:
///<summary>
///Representsacustomerofthesystem.
///</summary>
publicpartialclassCustomer
{
//Containsthemainfunctionalityoftheclass.
}
///<content>
///ImplementstheICollectionclass.
///</content>
publicpartialclassCustomer:ICollection
![Page 426: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/426.jpg)
{
publicintCount
{
get{returnthis.count;}
}
publicboolIsSynchronized
{
get{returnfalse;}
}
publicobjectSyncRoot
{
get{returnnull;}
}
publicvoidCopyTo(Arrayarray,intindex)
{
thrownewNotImplementedException();
}
![Page 427: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/427.jpg)
}
![Page 428: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/428.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,ordertheelementsinthefileintheorderdescribedabove.
![Page 429: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/429.jpg)
TypeName ElementsMustBeOrderedByAccess
CheckId SA1202
Category OrderingRules
![Page 430: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/430.jpg)
CauseAnelementwithinaC#codefileisoutoforderwithinregardtoaccesslevel,inrelationtootherelementsinthecode.
![Page 431: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/431.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodeelementswithinafiledonotfollowastandardorderingschemebasedonaccesslevel.
Tocomplywiththisrule,adjacentelementsofthesametypemustbepositionedinthefollowingorderbyaccesslevel:
public
internal
protectedinternal
protected
private
Complyingwithastandardorderingschemebasedonaccesslevelcanincreasethereadabilityandmaintainabilityofthefileandmakeiteasiertoidentifythepublicinterfacethatisbeingexposedfromaclass.
![Page 432: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/432.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,ordertheelementsinthefileintheorderdescribedabove.
![Page 433: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/433.jpg)
TypeName ConstantsMustAppearBeforeFields
CheckId SA1203
Category OrderingRules
![Page 434: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/434.jpg)
CauseAconstfieldisplacedbeneathanon-constfield.
![Page 435: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/435.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaconstfieldisplacedbeneathanon-constfield.Constantsmustbeplacedabovefieldstoindicatethatthetwoarefundamentallydifferenttypesofelementswithdifferentconsiderationsforthecompiler,differentnamingrequirements,etc.
![Page 436: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/436.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,placeallconstsaboveallfields.
![Page 437: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/437.jpg)
TypeName StaticElementsMustAppearBeforeInstanceElements
CheckId SA1204
Category OrderingRules
![Page 438: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/438.jpg)
CauseAstaticelementispositionedbeneathaninstanceelementofthesametype.
![Page 439: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/439.jpg)
RuleDescriptionAviolationofthisruleoccurswhenastaticelementispositionedbeneathaninstanceelementofthesametype.Allstaticelementsmustbeplacedaboveallinstanceelementsofthesametypetomakeiteasiertoseetheinterfaceexposedfromtheinstanceandstaticversionoftheclass.
![Page 440: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/440.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,placeallstaticelementsaboveallinstanceelementsofthesametype.
![Page 441: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/441.jpg)
TypeName PartialElementsMustDeclareAccess
CheckId SA1205
Category OrderingRules
![Page 442: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/442.jpg)
CauseThepartialelementdoesnothaveanaccessmodifierdefined.StyleCopmaynotbeabletodeterminethecorrectplacementoftheelementsinthefile.Pleasedeclareanaccessmodifierforallpartialelements.
![Page 443: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/443.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthepartialelementsdoesnothaveanaccessmodifierdefined.
![Page 444: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/444.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,specifyanacessmodifierforthepartialelement.
![Page 445: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/445.jpg)
TypeName DeclarationKeywordsMustFollowOrder
CheckId SA1206
Category OrderingRules
![Page 446: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/446.jpg)
CauseThekeywordswithinthedeclarationofanelementdonotfollowastandardorderingscheme.
![Page 447: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/447.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthekeywordswithinanelement’sdeclarationdonotfollowastandardorderingscheme.
Withinanelementdeclaration,keywordsmustappearinthefollowingorder:
Accessmodifiers
static
Allotherkeywords
Usingastandardorderingschemeforelementdeclarationkeywordscanmakethecodemorereadablebyhighlightingtheaccesslevelofeachelement.Thiscanhelppreventelementsfrombeinggivenahigheraccesslevelthanneeded.
![Page 448: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/448.jpg)
HowToFixViolationsTofixaninstanceofthisviolation,orderthekeywordsintheelement’sdeclarationasdescribedabove.
![Page 449: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/449.jpg)
TypeName ProtectedMustComeBeforeInternal
CheckId SA1207
Category OrderingRules
![Page 450: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/450.jpg)
CauseThekeywordprotectedispositionedafterthekeywordinternalwithinthedeclarationofaprotectedinternalC#element.
![Page 451: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/451.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaprotectedinternalelement’saccessmodifiersarewrittenasinternalprotected.Inreality,anelementwiththekeywordsprotectedinternalwillhavethesameaccesslevelasanelementwiththekeywordsinternalprotected.Tomakethecodeeasiertoreadandmoreconsistent,StyleCopstandardizestheorderingofthesekeywords,sothataprotectedinternalelementwillalwaysbedescribedassuch,andneverasinternalprotected.Thiscanhelptoreduceconfusionaboutwhethertheseaccesslevelsareindeedthesame.
![Page 452: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/452.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,placetheprotectedkeywordbeforetheinternalkeyword.
![Page 453: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/453.jpg)
TypeName SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives
CheckId SA1208
Category OrderingRules
![Page 454: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/454.jpg)
CauseAusingdirectivewhichdeclaresamemberoftheSystemnamespaceappearsafterausingdirectivewhichdeclaresamemberofadifferentnamespace,withinaC#codefile.
![Page 455: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/455.jpg)
RuleDescriptionAviolationofthisruleoccurswhenausingdirectivefortheSystemnamespaceisplacedafteranon-Systemusingdirective.PlacingallSystemusingdirectivesatthetopoftheusingdirectivescanmakethecodecleanerandeasiertoread,andcanhelpmakeiteasiertoidentifythenamespacesthatarebeingusedbythecode.
![Page 456: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/456.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,placetheSystemusingdirectiveaboveallusingdirectivesforothernamespaces.
![Page 457: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/457.jpg)
TypeName UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives
CheckId SA1209
Category OrderingRules
![Page 458: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/458.jpg)
CauseAusing-aliasdirectiveispositionedbeforearegularusingdirective.
![Page 459: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/459.jpg)
RuleDescriptionAviolationofthisruleoccurswhenausing-aliasdirectiveisplacedbeforeanormalusingdirective.Using-aliasdirectiveshavespecialbehaviorwhichcanalterthemeaningoftherestofthecodewithinthefileornamespace.Placingtheusing-aliasdirectivestogetherbelowallotherusing-directivescanmakethecodecleanerandeasiertoread,andcanhelpmakeiteasiertoidentifythetypesusedthroughoutthecode.
![Page 460: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/460.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,placeallusing-aliasdirectivesbeneathallnormalusingdirectives.
![Page 461: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/461.jpg)
TypeName UsingDirectivesMustBeOrderedAlphabeticallyByNamespace
CheckId SA1210
Category OrderingRules
![Page 462: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/462.jpg)
CauseTheusingdirectiveswithinaC#codefilearenotsortedalphabeticallybynamespace.
![Page 463: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/463.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheusingdirectivesarenotsortedalphabeticallybynamespace.Sortingtheusingdirectivesalphabeticallymakesthecodecleanerandeasiertoread,andcanhelpmakeiteasiertoidentifythenamespacesthatarebeingusedbythecode.TheSystemnamespacesareanexceptiontothisruleandwillalwaysprecedeallothernamespaces.SeeSA1208formoredetails.
![Page 464: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/464.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,ordertheusingdirectivesalphabeticallybynamespacewithalltheSystemnamespaceentriesfirst.
![Page 465: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/465.jpg)
TypeName UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName
CheckId SA1211
Category OrderingRules
![Page 466: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/466.jpg)
CauseTheusing-aliasdirectiveswithinaC#codefilearenotsortedalphabeticallybyaliasname.
![Page 467: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/467.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheusing-aliasdirectivesarenotsortedalphabeticallybyaliasname.Sortingtheusing-aliasdirectivesalphabeticallycanmakethecodecleanerandeasiertoread,andcanhelpmakeiteasiertoidentifythenamespacesthatarebeingusedbythecode.
![Page 468: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/468.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,ordertheusing-aliasdirectivesalphabeticallybyaliasname.
![Page 469: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/469.jpg)
TypeName PropertyAccessorsMustFollowOrder
CheckId SA1212
Category OrderingRules
![Page 470: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/470.jpg)
CauseAgetaccessorappearsafterasetaccessorwithinapropertyorindexer.
![Page 471: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/471.jpg)
RuleDescriptionAviolationofthisruleoccurswhenagetaccessorisplacedafterasetaccessorwithinapropertyorindexer.Tocomplywiththisrule,thegetaccessorshouldappearbeforethesetaccessor.
Forexample,thefollowingcodewouldraiseaninstanceofthisviolation:
publicstringName{
set{this.name=value;}
get{returnthis.name;}
}Thecodebelowwouldnotraisethisviolation:
publicstringName{get{returnthis.name;}
set{this.name=value;}
}
![Page 472: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/472.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,placethegetaccessorbeforethesetaccessor.
![Page 473: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/473.jpg)
TypeName EventAccessorsMustFollowOrder
CheckId SA1213
Category OrderingRules
![Page 474: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/474.jpg)
CauseAnaddaccessorappearsafteraremoveaccessorwithinanevent.
![Page 475: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/475.jpg)
RuleDescriptionAviolationofthisruleoccurswhenanaddaccessorisplacedafteraremoveaccessorwithinanevent.Tocomplywiththisrule,theaddaccessorshouldappearbeforetheremoveaccessor.
Forexample,thefollowingcodewouldraiseaninstanceofthisviolation:
publiceventEventHandlerNameChanged{
remove{this.nameChanged-=value;}
add{this.nameChanged+=value;}
}Thecodebelowwouldnotraisethisviolation:
publiceventEventHandlerNameChanged{add{this.nameChanged+=value;}
remove{this.nameChanged-=value;}
}
![Page 476: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/476.jpg)
HowtoFixViolationsTofixaninstanceofthisviolation,placetheaddaccessorbeforetheremoveaccessor.
![Page 477: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/477.jpg)
Ruleswhichensurethatthecodeiswell-formattedandreadable.
SA1100:DoNotPrefixCallsWithBaseUnlessLocalImplementationExists
SA1101:PrefixLocalCallsWithThis
SA1102:QueryClauseMustFollowPreviousClause
SA1103:QueryClausesMustBeOnSeparateLinesOrAllOnOneLine
SA1104:QueryClauseMustBeginOnNewLineWhenPreviousClauseSpansMultipleLines
SA1105:QueryClausesSpanningMultipleLinesMustBeginOnOwnLine
SA1106:CodeMustNotContainEmptyStatements
SA1107:CodeMustNotContainMultipleStatementsOnOneLine
SA1108:BlockStatementsMustNotContainEmbeddedComments
SA1109:BlockStatementsMustNotContainEmbeddedRegions
SA1110:OpeningParenthesisMustBeOnDeclarationLine
SA1111:ClosingParenthesisMustBeOnLineOfOpeningParenthesis
SA1112:ClosingParenthesisMustBeOnLineOfOpeningParenthesis
SA1113:CommaMustBeOnSameLineAsPreviousParameter
SA1114:ParameterListMustFollowDeclaration
SA1115:ParameterMustFollowComma
SA1116:SplitParametersMustStartOnLineAfterDeclaration
SA1117:ParametersMustBeOnSameLineOrSeparateLines
SA1118:ParameterMustNotSpanMultipleLines
SA1120:CommentsMustContainText
SA1121:UseBuiltInTypeAlias
SA1122:UseStringEmptyForEmptyStrings
SA1123:DoNotPlaceRegionsWithinElements
SA1124:DoNotUseRegions
![Page 478: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/478.jpg)
SA1125:UseShorthandForNullableTypes
![Page 479: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/479.jpg)
TypeName DoNotPrefixCallsWithBaseUnlessLocalImplementationExists
CheckId SA1100
Category ReadabilityRules
![Page 480: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/480.jpg)
CauseAcalltoamemberfromaninheritedclassbeginswith‘base.’,andthelocalclassdoesnotcontainanoverrideorimplementationofthemember.
![Page 481: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/481.jpg)
RuleDescriptionAviolationofthisruleoccurswheneverthecodecontainsacalltoamemberfromthebaseclassprefixedwith‘base.’,andthereisnolocalimplementationofthemember.Forexample:
stringname=base.JoinName("John","Doe");
Thisruleisinplacetopreventapotentialsourceofbugs.Considerabaseclasswhichcontainsthefollowingvirtualmethod:
publicvirtualstringJoinName(stringfirst,stringlast)
{
}
Anotherclassinheritsfromthisbaseclassbutdoesnotprovidealocaloverrideofthismethod.Somewherewithinthisclass,thebaseclassmethodiscalledusingbase.JoinName(...).Thisworksasexpected.Atalaterdate,someoneaddsalocaloverrideofthismethodtotheclass:
publicoverridestringJoinName(stringfirst,stringlast)
{
return“Bob”;
}
Atthispoint,thelocalcalltobase.JoinName(...)mostlikelyintroducesabugintothecode.Thiscallwillalwayscallthebaseclassmethodandwillcausethelocaloverridetobeignored.
Forthisreason,callstomembersfromabaseclassshouldnotbeginwith‘base.’,unlessalocaloverrideisimplemented,andthedeveloperwantsto
![Page 482: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/482.jpg)
specificallycallthebaseclassmember.Whenthereisnolocaloverrideofthebaseclassmember,thecallshouldbeprefixedwith'this.'ratherthan'base.'.
![Page 483: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/483.jpg)
HowtoFixViolationsTofixaviolationofthisrule,changethe‘base.’prefixto‘this.’.
![Page 484: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/484.jpg)
TypeName PrefixLocalCallsWithThis
CheckId SA1101
Category ReadabilityRules
![Page 485: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/485.jpg)
CauseAcalltoaninstancememberofthelocalclassorabaseclassisnotprefixedwith‘this.’,withinaC#codefile.
![Page 486: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/486.jpg)
RuleDescriptionAviolationofthisruleoccurswheneverthecodecontainsacalltoaninstancememberofthelocalclassorabaseclasswhichisnotprefixedwith‘this.’.Anexceptiontothisruleoccurswhenthereisalocaloverrideofabaseclassmember,andthecodeintendstocallthebaseclassmemberdirectly,bypassingthelocaloverride.Inthiscasethecallcanbeprefixedwith‘base.’ratherthan‘this.’.
Bydefault,StyleCopdisallowstheuseofunderscoresorm_tomarklocalclassfields,infavorofthe‘this.’prefix.Theadvantageofusing‘this.’isthatitappliesequallytoallelementtypesincludingmethods,properties,etc.,andnotjustfields,makingallcallstoclassmembersinstantlyrecognizable,regardlessofwhicheditorisbeingusedtoviewthecode.Anotheradvantageisthatitcreatesaquick,recognizabledifferentiationbetweeninstancemembersandstaticmembers,whicharenotbeprefixed.
Afinaladvantageofusingthe‘this.’prefixisthattypingthis.willcauseVisualStudiotoshowtheIntelliSensepopup,makingitquickandeasyforthedevelopertochoosetheclassmembertocall.
![Page 487: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/487.jpg)
HowtoFixViolationsTofixaviolationofthisrule,insertthe‘this.’prefixbeforethecalltotheclassmember.
![Page 488: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/488.jpg)
TypeName QueryClauseMustFollowPreviousClause
CheckId SA1102
Category ReadabilityRules
![Page 489: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/489.jpg)
CauseAC#queryclausedoesnotbeginonthesamelineasthepreviousclause,oronthenextline.
![Page 490: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/490.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaclausewithinaqueryexpressiondoesnotbeginonthesamelineasthepreviousclause,oronthelineafterthequeryclause.Forexample:
objectx=selectainb
fromc;
Thequeryclausecancorrectlybewrittenas:
objectx=selectainbfromc;
or:
objectx=
selecta
inb
fromc;
![Page 491: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/491.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethateachclauseinthequeryexpressionbeginsonthesamelineasthepreviousclause,oronthefollowingline.
![Page 492: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/492.jpg)
TypeName QueryClausesMustBeOnSeparateLinesOrAllOnOneLine
CheckId SA1103
Category ReadabilityRules
![Page 493: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/493.jpg)
CauseTheclauseswithinaC#queryexpressionarenotallplacedonthesameline,andeachclauseisnotplacedonitsownline.
![Page 494: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/494.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthequeryclausesarenoteitherplacedallonthesameline,oreachonitsownline.Forexample:
objectx=selectainb
fromc;
Thequeryclausecancorrectlybewrittenas:
objectx=selectainbfromc;
or:
objectx=
selecta
inb
fromc;
![Page 495: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/495.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatallclausesareplacedtogetheronthesameline,oreachclausebeginsonitsownline.
![Page 496: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/496.jpg)
TypeName QueryClauseMustBeginOnNewLineWhenPreviousClauseSpansMultipleLines
CheckId SA1104
Category ReadabilityRules
![Page 497: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/497.jpg)
CauseAclausewithinaC#queryexpressionbeginsonthesamelineasthepreviousclause,whenthepreviousclausespansacrossmultiplelines.
![Page 498: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/498.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaqueryclausespansacrossmultiplelines,andthenextclausebeginsonthesamelineastheendofthepreviousclause.
objectx=
selecta
inb.GetCustomers(
2,“x”)fromc;
Thequeryclausecancorrectlybewrittenas:
objectx=
selecta
inb.GetCustomers(
2,“x”)
fromc;
![Page 499: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/499.jpg)
HowtoFixViolationsTofixaviolationofthisrule,movetheclausedowntostartonthenextline.
![Page 500: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/500.jpg)
TypeName QueryClausesSpanningMultipleLinesMustBeginOnOwnLine
CheckId SA1105
Category ReadabilityRules
![Page 501: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/501.jpg)
CauseAclausewithinaC#queryexpressionspansacrossmultiplelines,anddoesnotbeginonitsownline.
![Page 502: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/502.jpg)
RuleDescriptionAviolationofthisruleoccurswhenaqueryclausespansacrossmultiplelines,butdoesnotbeginonitsownline.Forexample:
objectx=
selectainbfromc.GetCustomers(
2,“x”);
Thequeryclausecancorrectlybewrittenas:
objectx=
selecta
inbfromc.GetCustomers(
2,“x”);
![Page 503: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/503.jpg)
HowtoFixViolationsTofixaviolationofthisrule,movetheclausedowntostartonthenextline.
![Page 504: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/504.jpg)
TypeName CodeMustNotContainEmptyStatements
CheckId SA1106
Category ReadabilityRules
![Page 505: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/505.jpg)
CauseTheC#codecontainsanextrasemicolon.
![Page 506: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/506.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainanextrasemicolon.Syntactically,thisresultsinanextra,emptystatementinthecode.
![Page 507: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/507.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheunneededsemicolon.
![Page 508: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/508.jpg)
TypeName CodeMustNotContainMultipleStatementsOnOneLine
CheckId SA1107
Category ReadabilityRules
![Page 509: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/509.jpg)
CauseTheC#codecontainsmorethanonestatementonasingleline.
![Page 510: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/510.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainmorethanonestatementonthesameline.Eachstatementmustbeginonanewline.
![Page 511: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/511.jpg)
HowtoFixViolationsTofixaviolationofthisrule,moveeachstatementtobeginonitsownline.
![Page 512: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/512.jpg)
TypeName BlockStatementsMustNotContainEmbeddedComments
CheckId SA1108
Category ReadabilityRules
![Page 513: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/513.jpg)
CauseAC#statementcontainsacommentbetweenthedeclarationofthestatementandtheopeningcurlybracketofthestatement.
![Page 514: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/514.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainsacommentinbetweenthedeclarationandtheopeningcurlybracket.Forexample:
if(x!=y)
//Makesurexdoesnotequaly
{
}
Thecommentcanlegallybeplacedabovethestatement,orwithinthebodyofthestatement:
//Makesurexdoesnotequaly
if(x!=y)
{
}
if(x!=y)
{
//Makesurexdoesnotequaly
}
Ifthecommentisbeingusedtocommentoutalineofcode,beginthecommentwithfourforwardslashesratherthantwo:
if(x!=y)
![Page 515: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/515.jpg)
////if(x==y)
{
}
![Page 516: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/516.jpg)
HowtoFixViolationsTofixaviolationofthisrule,movethecommentabovethestatement,withinthebodyofthestatement,orremovethecomment.
![Page 517: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/517.jpg)
TypeName BlockStatementsMustNotContainEmbeddedRegions
CheckId SA1109
Category ReadabilityRules
![Page 518: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/518.jpg)
CauseAC#statementcontainsaregiontagbetweenthedeclarationofthestatementandtheopeningcurlybracketofthestatement.
![Page 519: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/519.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainsaregiontaginbetweenthedeclarationandtheopeningcurlybracket.Forexample:
if(x!=y)
#region
{
}
#endregion
Thiswillresultinthebodyofthestatementbeinghiddenwhentheregioniscollapsed.
![Page 520: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/520.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheregionormoveitoutsideofthestatement.
![Page 521: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/521.jpg)
TypeName OpeningParenthesisMustBeOnDeclarationLine
CheckId SA1110
Category ReadabilityRules
![Page 522: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/522.jpg)
CauseTheopeningparenthesisorbracketinacalltoaC#methodorindexer,orthedeclarationofamethodorindexer,isnotplacedonthesamelineasthemethodorindexername.
![Page 523: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/523.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheopeningbracketofamethodorindexercallordeclarationisnotplacedonthesamelineasthemethodorindexer.Thefollowingexamplesshowcorrectplacementoftheopeningbracket:
publicstringJoinName(stringfirst,stringlast)
{
returnJoinStrings(
first,last);
}
publicintthis[intx]
{
get{returnthis.items[x];}
}
![Page 524: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/524.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethattheopeningbracketisplacedonthesamelineasthenameofthemethodorindexer.
![Page 525: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/525.jpg)
TypeName ClosingParenthesisMustBeOnLineOfLastParameter
CheckId SA1111
Category ReadabilityRules
![Page 526: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/526.jpg)
CauseTheclosingparenthesisorbracketinacalltoaC#methodorindexer,orthedeclarationofamethodorindexer,isnotplacedonthesamelineasthelastparameter.
![Page 527: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/527.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheclosingbracketofamethodorindexercallordeclarationisnotplacedonthesamelineasthelastparameter.Thefollowingexamplesshowcorrectplacementofthebracket:
publicstringJoinName(stringfirst,stringlast)
{
stringname=JoinStrings(
first,
last);
}
publicintthis[intx]
{
get{returnthis.items[x];}
}
![Page 528: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/528.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethattheclosingbracketisplacedonthesamelineasthelastparameter.
![Page 529: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/529.jpg)
TypeName ClosingParenthesisMustBeOnLineOfOpeningParenthesis
CheckId SA1112
Category ReadabilityRules
![Page 530: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/530.jpg)
CauseTheclosingparenthesisorbracketinacalltoaC#methodorindexer,orthedeclarationofamethodorindexer,isnotplacedonthesamelineastheopeningbracketwhentheelementdoesnottakeanyparameters.
![Page 531: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/531.jpg)
RuleDescriptionAviolationofthisruleoccurswhenamethodorindexerdoesnottakeanyparametersandtheclosingbracketofacallordeclarationforthemethodorindexerisnotplacedonthesamelineastheopeningbracket.Thefollowingexampleshowscorrectplacementoftheclosingparenthesis:
publicstringGetName()
{
returnthis.name.Trim();
}
![Page 532: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/532.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethattheclosingbracketisplacedonthesamelineastheopeningbracket.
![Page 533: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/533.jpg)
TypeName CommaMustBeOnSameLineAsPreviousParameter
CheckId SA1113
Category ReadabilityRules
![Page 534: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/534.jpg)
CauseAcommabetweentwoparametersinacalltoaC#methodorindexer,orinthedeclarationofamethodorindexer,isnotplacedonthesamelineasthepreviousparameter.
![Page 535: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/535.jpg)
RuleDescriptionAviolationofthisruleoccurswhenacommabetweentwoparameterstoamethodorindexerisnotplacedonthesamelineasthepreviousparameter.Thefollowingexamplesshowcorrectplacementofthecomma:
publicstringJoinName(stringfirst,stringlast)
{
stringname=JoinStrings(
first,
last);
}
publicintthis[intx,
inty]
{
get{returnthis.items[x,y];}
}
![Page 536: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/536.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthecommaisplacedonthesamelineasthepreviousparameter.
![Page 537: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/537.jpg)
TypeName ParameterListMustFollowDeclaration
CheckId SA1114
Category ReadabilityRules
![Page 538: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/538.jpg)
CauseThestartoftheparameterlistforamethodorindexercallordeclarationdoesnotbeginonthesamelineastheopeningbracket,oronthelineaftertheopeningbracket.
![Page 539: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/539.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthereareoneormoreblanklinesbetweentheopeningbracketandthestartoftheparameterlist.Forexample:
publicstringJoinName(
stringfirst,stringlast)
{
}
Theparameterlistmustbeginonthesamelineastheopeningbracket,oronthenextline.Forexample:
publicstringJoinName(stringfirst,stringlast)
{
}
publicstringJoinName(
stringfirst,stringlast)
{
}
![Page 540: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/540.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethattheparameterlistbeginsonthesamelineastheopeningbracket,oronthenextline.
![Page 541: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/541.jpg)
TypeName ParameterMustFollowComma
CheckId SA1115
Category ReadabilityRules
![Page 542: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/542.jpg)
CauseAparameterwithinaC#methodorindexercallordeclarationdoesnotbeginonthesamelineasthepreviousparameter,oronthenextline.
![Page 543: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/543.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthereareoneormoreblanklinesbetweenaparameterandthepreviousparameter.Forexample:
publicstringJoinName(
stringfirst,
stringlast)
{
}
Theparametermustbeginonthesamelineasthepreviouscomma,oronthenextline.Forexample:
publicstringJoinName(stringfirst,stringlast)
{
}
publicstringJoinName(
stringfirst,
stringlast)
{
}
![Page 544: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/544.jpg)
![Page 545: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/545.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethattheparameterbeginsonthesamelineasthepreviouscomma,oronthenextline.
![Page 546: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/546.jpg)
TypeName SplitParametersMustStartOnLineAfterDeclaration
CheckId SA1116
Category ReadabilityRules
![Page 547: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/547.jpg)
CauseTheparameterstoaC#methodorindexercallordeclarationspanacrossmultiplelines,butthefirstparameterdoesnotstartonthelineaftertheopeningbracket.
![Page 548: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/548.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheparameterstoamethodorindexerspanacrossmultiplelines,butthefirstparameterdoesnotstartonthelineaftertheopeningbracket.Forexample:
publicstringJoinName(stringfirst,
stringlast)
{
}
Theparametersmustbeginonthelineafterthedeclaration,whenevertheparameterspanacrossmultiplelines:
publicstringJoinName(
stringfirst,
stringlast)
{
}
![Page 549: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/549.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthefirstparameterstartsonthelineaftertheopeningbracket,orplaceallparametersonthesamelineiftheparametersarenottoolong.
![Page 550: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/550.jpg)
TypeName ParametersMustBeOnSameLineOrSeparateLines
CheckId SA1117
Category ReadabilityRules
![Page 551: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/551.jpg)
CauseTheparameterstoaC#methodorindexercallordeclarationarenotallonthesamelineoreachonaseparateline.
![Page 552: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/552.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheparameterstoamethodorindexerarenotallonthesamelineoreachonitsownline.Forexample:
publicstringJoinName(stringfirst,stringmiddle,
stringlast)
{
}
Theparameterscanallbeplacedonthesameline:
publicstringJoinName(stringfirst,stringmiddle,stringlast)
{
}
publicstringJoinName(
stringfirst,stringmiddle,stringlast)
{
}
Alternatively,eachparametercanbeplacedonitsownline:
publicstringJoinName(
stringfirst,
stringmiddle,
stringlast)
![Page 553: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/553.jpg)
{
}
![Page 554: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/554.jpg)
HowtoFixViolationsTofixaviolationofthisrule,placeallparametersonthesameline,orplaceeachparameteronitsownline.
![Page 555: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/555.jpg)
TypeName ParameterMustNotSpanMultipleLines
CheckId SA1118
Category ReadabilityRules
![Page 556: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/556.jpg)
CauseAparametertoaC#methodorindexer,otherthanthefirstparameter,spansacrossmultiplelines.
![Page 557: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/557.jpg)
RuleDescriptionTopreventmethodcallsfrombecomingexcessivelycomplicatedandunreadable,onlythefirstparametertoamethodorindexercallisallowedtospanacrossmultiplelines.Theexceptionisananonymousmethodpassedasaparameter,whichisalwaysallowedtospanmultiplelines.Aviolationofthisruleoccurswheneveraparameterotherthanthefirstparameterspansacrossmultiplelines,andtheparameterdoesnotcontainananonymousmethod.
Forexample,thefollowingcodewouldviolatethisrule,sincethesecondparameterspansacrossmultiplelines:
returnJoinStrings(
"John",
"Smith"+
"Doe");
Whenparametersotherthanthefirstparameterspanacrossmultiplelines,itcanbedifficulttotellhowmanyparametersarepassedtothemethod.Ingeneral,thecodebecomesdifficulttoread.
Tofixtheexampleabove,ensurethattheparametersafterthefirstparameterdonotspanacrossmultiplelines.Ifthiswillcauseaparametertobeexcessivelylong,storethevalueoftheparameterwithinatemporaryvariable.Forexample:
stringlast="Smith"+
"Doe";
returnJoinStrings(
"John",
![Page 558: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/558.jpg)
last);
Insomecases,thiswillallowthemethodtobewrittenevenmoreconcisely,suchas:
returnJoinStrings("John",last);
![Page 559: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/559.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethattheparametersafterthefirstparameterdonotspanmultiplelines,unlesstheparametercontainsananonymousmethod.
![Page 560: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/560.jpg)
TypeName CommentsMustContainText
CheckId SA1120
Category ReadabilityRules
![Page 561: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/561.jpg)
CauseTheC#commentdoesnotcontainanycommenttext.
![Page 562: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/562.jpg)
RuleDescriptionAviolationofthisruleoccurswheneverthecodecontainsaC#commentwhichdoesnotcontainanytext.
![Page 563: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/563.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addtexttothecomment,orremovethecomment.
![Page 564: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/564.jpg)
TypeName UseBuiltInTypeAlias
CheckId SA1121
Category ReadabilityRules
![Page 565: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/565.jpg)
CauseThecodeusesoneofthebasicC#types,butdoesnotusethebuilt-inaliasforthetype.
![Page 566: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/566.jpg)
RuleDescriptionAviolationofthisruleoccurswhenoneofthefollowingtypesareusedanywhereinthecode:Boolean,Byte,Char,Decimal,Double,Int16,Int32,Int64,Object,SByte,Single,String,UInt16,UInt32,UInt64.
Aviolationalsooccurswhenanyofthesetypesarerepresentedinthecodeusingthefullnamespaceforthetype: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.
Ratherthanusingthetypenameorthefully-qualifiedtypename,thebuilt-inaliasesforthesetypesshouldalwaysbeused:bool,byte,char,decimal,double,short,int,long,object,sbyte,float,string,ushort,uint,ulong.
Thefollowingtablelistseachofthesetypesinallthreeformats:
TypeAlias Type FullyQualifiedType
bool Boolean System.Boolean
byte Byte System.Byte
char Char System.Char
decimal Decimal System.Decimal
double Double System.Double
short Int16 System.Int16
int Int32 System.Int32
long Int64 System.Int64
object Object System.Object
sbyte SByte System.SByte
float Single System.Single
string String System.String
ushort UInt16 System.UInt16
uint UInt32 System.UInt32
![Page 567: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/567.jpg)
ulong UInt64 System.UInt64
![Page 568: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/568.jpg)
HowtoFixViolationsTofixaviolationofthisrule,replacethetypewiththebuilt-inaliasforthetype.
![Page 569: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/569.jpg)
TypeName UseStringEmptyForEmptyStrings
CheckId SA1122
Category ReadabilityRules
![Page 570: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/570.jpg)
CauseTheC#codeincludesanemptystring,writtenas“”.
![Page 571: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/571.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthecodecontainsanemptystring.Forexample:
strings="";
Thiswillcausethecompilertoembedanemptystringintothecompiledcode.Ratherthanincludingahard-codedemptystring,usethestaticstring.Emptyproperty:
strings=string.Empty;
![Page 572: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/572.jpg)
HowtoFixViolationsTofixaviolationofthisrule,replacethehard-codedemptystringwithstring.Empty.
![Page 573: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/573.jpg)
TypeName DoNotPlaceRegionsWithinElements
CheckId SA1123
Category ReadabilityRules
![Page 574: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/574.jpg)
CauseTheC#codecontainsaregionwithinthebodyofacodeelement.
![Page 575: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/575.jpg)
RuleDescriptionAviolationofthisruleoccurswheneveraregionisplacedwithinthebodyofacodeelement.Inmanyeditors,includingVisualStudio,theregionwillappearcollapsedbydefault,hidingthecodewithintheregion.Itisgenerallyabadpracticetohidecodewithinthebodyofanelement,asthiscanleadtobaddecisionsasthecodeismaintainedovertime.
![Page 576: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/576.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheregionfromthecode.
![Page 577: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/577.jpg)
TypeName DoNotUseRegions
CheckId SA1124
Category ReadabilityRules
![Page 578: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/578.jpg)
CauseTheC#codecontainsaregion.
![Page 579: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/579.jpg)
RuleDescriptionAviolationofthisruleoccurswheneveraregionisplacedanywherewithinthecode.Inmanyeditors,includingVisualStudio,theregionwillappearcollapsedbydefault,hidingthecodewithintheregion.Itisgenerallyabadpracticetohidecode,asthiscanleadtobaddecisionsasthecodeismaintainedovertime.
![Page 580: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/580.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheregionfromthecode.
![Page 581: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/581.jpg)
TypeName UseShorthandForNullableTypes
CheckId SA1125
Category ReadabilityRules
![Page 582: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/582.jpg)
CauseTheNullabletypehasbeendefinednotusingtheC#shorthand.Forexample,Nullable<DateTime>hasbeenusedinsteadofthepreferredDateTime?
![Page 583: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/583.jpg)
RuleDescriptionAviolationofthisruleoccurswhenevertheNullabletypehasbeendefinedwithoutusingtheshorthandC#style.
![Page 584: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/584.jpg)
HowtoFixViolationsTofixaviolationofthisrule,usetheshorthandversionofthenullabletypeie.int?,DateTime?,etc.
![Page 585: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/585.jpg)
Ruleswhichenforcespacingrequirementsaroundkeywordsandsymbolsinthecode.
SA1000:KeywordsMustBeSpacedCorrectly
SA1001:CommasMustBeSpacedCorrectly
SA1002:SemicolonsMustBeSpacedCorrectly
SA1003:SymbolsMustBeSpacedCorrectly
SA1004:DocumentationLinesMustBeginWithSingleSpace
SA1005:SingleLineCommentsMustBeginWithSingeSpace
SA1006:PreprocessorKeywordsMustNotBePrecededBySpace
SA1007:OperatorKeywordMustBeFollowedBySpace
SA1008:OpeningParenthesisMustBeSpacedCorrectly
SA1009:ClosingParenthesisMustBeSpacedCorrectly
SA1010:OpeningSquareBracketsMustBeSpacedCorrectly
SA1011:ClosingSquareBracketsMustBeSpacedCorrectly
SA1012:OpeningCurlyBracketsMustBeSpacedCorrectly
SA1013:ClosingCurlyBracketsMustBeSpacedCorrectly
SA1014:OpeningGenericBracketsMustBeSpacedCorrectly
SA1015:ClosingGenericBracketsMustBeSpacedCorrectly
SA1016:OpeningAttributeBracketsMustBeSpacedCorrectly
SA1017:ClosingAttributeBracketsMustBeSpacedCorrectly
SA1018:NullableTypeSymbolsMustNotBePrecededBySpace
SA1019:MemberAccessSymbolsMustBeSpacedCorrectly
SA1020:IncrementDecrementSymbolsMustBeSpacedCorrectly
SA1021:NegativeSignsMustBeSpacedCorrectly
SA1022:PositiveSignsMustBeSpacedCorrectly
SA1023:DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly
![Page 586: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/586.jpg)
SA1024:ColonsMustBeSpacedCorrectly
SA1025:CodeMustNotContainMultipleWhitespaceInARow
SA1026:CodeMustNotContainSpaceAfterNewKeywordInImplicitlyTypedArrayAllocation
SA1027:TabsMustNotBeUsed
![Page 587: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/587.jpg)
TypeName KeywordsMustBeSpacedCorrectly
CheckId SA1000
Category SpacingRules
![Page 588: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/588.jpg)
CauseThespacingaroundaC#keywordisincorrect.
![Page 589: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/589.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundakeywordisincorrect.
ThefollowingC#keywordsmustalwaysbefollowedbyasinglespace:catch,fixed,for,foreach,from,group,if,in,into,join,let,lock,orderby,return,select,stackalloc,switch,throw,using,where,while,yield.
Thefollowingkeywordsmustnotbefollowedbyanyspace:checked,default,sizeof,typeof,unchecked.
Thenewkeywordshouldalwaysbefollowedbyaspace,unlessitisusedtocreateanewarray,inwhichcasethereshouldbenospacebetweenthenewkeywordandtheopeningarraybracket.
![Page 590: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/590.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addorremoveaspaceafterthekeyword,accordingtothedescriptionabove.
![Page 591: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/591.jpg)
TypeName CommasMustBeSpacedCorrectly
CheckId SA1001
Category SpacingRules
![Page 592: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/592.jpg)
CauseThespacingaroundacommaisincorrect,withinaC#codefile.
![Page 593: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/593.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundacommaisincorrect.
Acommashouldalwaysbefollowedbyasinglespace,unlessitisthelastcharacterontheline,andacommashouldneverbeprecededbyanywhitespace,unlessitisthefirstcharacterontheline.
![Page 594: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/594.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthecommaisfollowedbyasinglespace,andisnotprecededbyanyspace.
![Page 595: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/595.jpg)
TypeName SemicolonsMustBeSpacedCorrectly
CheckId SA1002
Category SpacingRules
![Page 596: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/596.jpg)
CauseThespacingaroundasemicolonisincorrect,withinaC#codefile.
![Page 597: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/597.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundasemicolonisincorrect.
Asemicolonshouldalwaysbefollowedbyasinglespace,unlessitisthelastcharacterontheline,andasemicolonshouldneverbeprecededbyanywhitespace,unlessitisthefirstcharacterontheline.
![Page 598: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/598.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthesemicolonisfollowedbyasinglespace,andisnotprecededbyanyspace.
![Page 599: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/599.jpg)
TypeName SymbolsMustBeSpacedCorrectly
CheckId SA1003
Category SpacingRules
![Page 600: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/600.jpg)
CauseThespacingaroundanoperatorsymbolisincorrect,withinaC#codefile.
![Page 601: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/601.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundanoperatorsymbolisincorrect.
Thefollowingtypesofoperatorsymbolsmustbesurroundedbyasinglespaceoneitherside:colons,arithmeticoperators,assignmentoperators,conditionaloperators,logicaloperators,relationaloperators,shiftoperators,andlambdaoperators.Forexample:
intx=4+y;
Incontrast,unaryoperatorsmustbeprecededbyasinglespace,butmustneverbefollowedbyanyspace.Forexample:
boolx=!value;
Anexceptionoccurswheneverthesymbolisprecededorfollowedbyaparenthesisorbracket,inwhichcasethereshouldbenospacebetweenthesymbolandthebracket.Forexample:
if(!value)
{
}
![Page 602: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/602.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundthesymbolfollowstheruledescribedabove.
![Page 603: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/603.jpg)
TypeName DocumentationLinesMustBeginWithSingleSpace
CheckId SA1004
Category SpacingRules
![Page 604: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/604.jpg)
CauseAlinewithinadocumentationheaderaboveaC#elementdoesnotbeginwithasinglespace.
![Page 605: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/605.jpg)
RuleDescriptionAviolationofthisruleoccurswhenalinewithinadocumentationheaderdoesnotbeginwithasinglespace.Forexample:
///<summary>
///Thesummarytext.
///</summary>
///<paramname="x">Thedocumentroot.</param>
///<paramname="y">TheXmlheadertoken.</param>
privatevoidMethod1(intx,inty)
{
}
Theheaderlinesshouldbeginwithasinglespaceafterthethreeleadingforwardslashes:
///<summary>
///Thesummarytext.
///</summary>
///<paramname="x">Thedocumentroot.</param>
///<paramname="y">TheXmlheadertoken.</param>
privatevoidMethod1(intx,inty)
{
![Page 606: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/606.jpg)
}
![Page 607: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/607.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethattheheaderlinebeginswithasinglespace.
![Page 608: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/608.jpg)
TypeName SingleLineCommentsMustBeginWithSingleSpace
CheckId SA1005
Category SpacingRules
![Page 609: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/609.jpg)
CauseAsingle-linecommentwithinaC#codefiledoesnotbeginwithasinglespace.
![Page 610: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/610.jpg)
RuleDescriptionAviolationofthisruleoccurswhenasingle-linecommentdoesnotbeginwithasinglespace.Forexample:
privatevoidMethod1()
{
//Asingle-linecomment.
//Asingle-linecomment.
}
Thecommentsshouldbeginwithasinglespaceaftertheleadingforwardslashes:
privatevoidMethod1()
{
//Asingle-linecomment.
//Asingle-linecomment.
}
Anexceptiontothisruleoccurswhenthecommentisbeingusedtocommentoutalineofcode.Inthiscase,thespacecanbeomittedifthecommentbeginswithfourforwardslashestoindicateout-commentedcode.Forexample:
privatevoidMethod1()
{
![Page 611: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/611.jpg)
////intx=2;
////returnx;
}
![Page 612: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/612.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthecommentbeginswithasinglespace.Ifthecommentisbeingusedtocommentoutalineofcode,ensurethatthecommentbeginswithfourforwardslashes,inwhichcasetheleadingspacecanbeomitted.
![Page 613: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/613.jpg)
TypeName PreprocessorKeywordsMustNotBePrecededBySpace
CheckId SA1006
Category SpacingRules
![Page 614: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/614.jpg)
CauseAC#preprocessor-typekeywordisprecededbyspace.
![Page 615: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/615.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthepreprocessor-typekeywordinapreprocessordirectiveisprecededbyspace.Forexample:
#ifDebug
Thereshouldnotbeanywhitespacebetweentheopeninghashmarkandthepreprocessor-typekeyword:
#ifDebug
![Page 616: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/616.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespacebetweentheopeninghashmarkandthepreprocessor-typekeyword.
![Page 617: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/617.jpg)
TypeName OperatorKeywordMustBeFollowedBySpace
CheckId SA1007
Category SpacingRules
![Page 618: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/618.jpg)
CauseTheoperatorkeywordwithinaC#operatoroverloadmethodisnotfollowedbyanywhitespace.
![Page 619: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/619.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheoperatorkeywordwithinanoperatoroverloadmethodisnotfollowedbyanywhitespace.Theoperatorkeywordshouldalwaysbefollowedbyasinglespace.Forexample:
publicMyClassoperator+(MyClassa,MyClassb)
{
}
![Page 620: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/620.jpg)
HowtoFixViolationsTofixaviolationofthisrule,addasinglespaceaftertheoperatorkeyword.
![Page 621: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/621.jpg)
TypeName OpeningParenthesisMustBeSpacedCorrectly
CheckId SA1008
Category SpacingRules
![Page 622: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/622.jpg)
CauseAnopeningparenthesiswithinaC#statementisnotspacedcorrectly.
![Page 623: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/623.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheopeningparenthesiswithinastatementisnotspacedcorrectly.Anopeningparenthesisshouldnotbeprecededbyanywhitespace,unlessitisthefirstcharacterontheline,oritisprecededbycertainC#keywordssuchasif,while,orfor.Inaddition,anopeningparenthesisisallowedtobeprecededbywhitespacewhenitfollowsanoperatorsymbolwithinanexpression.
Anopeningparenthesisshouldnotbefollowedbywhitespace,unlessitisthelastcharacterontheline.
![Page 624: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/624.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundtheopeningparenthesisfollowstheruledescribedabove.
![Page 625: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/625.jpg)
TypeName ClosingParenthesisMustBeSpacedCorrectly
CheckId SA1009
Category SpacingRules
![Page 626: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/626.jpg)
CauseAclosingparenthesiswithinaC#statementisnotspacedcorrectly.
![Page 627: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/627.jpg)
RuleDescriptionAviolationofthisruleoccurswhentheclosingparenthesiswithinastatementisnotspacedcorrectly.
Aclosingparenthesisshouldneverbeprecededbywhitespace.Inmostcases,aclosingparenthesisshouldbefollowedbyasinglespace,unlesstheclosingparenthesiscomesattheendofacast,ortheclosingparenthesisisfollowedbycertaintypesofoperatorsymbols,suchaspositivesigns,negativesigns,andcolons.
Iftheclosingparenthesisisfollowedbywhitespace,thenextnon-whitespacecharactermustnotbeanopeningorclosingparenthesisorsquarebracket,orasemicolonorcomma.
![Page 628: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/628.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundtheclosingparenthesisfollowstheruledescribedabove.
![Page 629: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/629.jpg)
TypeName OpeningSquareBracketsMustBeSpacedCorrectly
CheckId SA1010
Category SpacingRules
![Page 630: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/630.jpg)
CauseAnopeningsquarebracketwithinaC#statementisnotspacedcorrectly.
![Page 631: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/631.jpg)
RuleDescriptionAviolationofthisruleoccurswhenanopeningsquarebracketwithinastatementisprecededorfollowedbywhitespace.
Anopeningsquarebracketmustneverbeprecededbywhitespace,unlessitisthefirstcharacterontheline,andanopeningsquaremustneverbefollowedbywhitespace,unlessitisthelastcharacterontheline.
![Page 632: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/632.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespaceoneithersideoftheopeningsquarebracket.
![Page 633: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/633.jpg)
TypeName ClosingSquareBracketsMustBeSpacedCorrectly
CheckId SA1011
Category SpacingRules
![Page 634: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/634.jpg)
CauseAclosingsquarebracketwithinaC#statementisnotspacedcorrectly.
![Page 635: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/635.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundaclosingsquarebracketisnotcorrect.
Aclosingsquarebracketmustneverbeprecededbywhitespace,unlessitisthefirstcharacterontheline.
Aclosingsquarebracketmustbefollowedbywhitespace,unlessitisthelastcharacterontheline,itisfollowedbyaclosingbracketoranopeningparenthesis,itisfollowedbyacommaorsemicolon,oritisfollowedbycertaintypesofoperatorsymbols.
![Page 636: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/636.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundtheclosingsquarebracketfollowstheruledescribedabove.
![Page 637: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/637.jpg)
TypeName OpeningCurlyBracketsMustBeSpacedCorrectly
CheckId SA1012
Category SpacingRules
![Page 638: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/638.jpg)
CauseAnopeningcurlybracketwithinaC#elementisnotspacedcorrectly.
![Page 639: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/639.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundanopeningcurlybracketisnotcorrect.
Anopeningcurlybracketshouldalwaysbeprecededbyasinglespace,unlessitisthefirstcharacterontheline,orunlessitisprecededbyanopeningparenthesis,inwhichcasethereshouldbenospacebetweentheparenthesisandthecurlybracket.
Anopeningcurlybracketmustalwaysbefollowedbyasinglespace,unlessitisthelastcharacterontheline.
![Page 640: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/640.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundtheopeningcurlybracketfollowstheruledescribedabove.
![Page 641: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/641.jpg)
TypeName ClosingCurlyBracketsMustBeSpacedCorrectly
CheckId SA1013
Category SpacingRules
![Page 642: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/642.jpg)
CauseAclosingcurlybracketwithinaC#elementisnotspacedcorrectly.
![Page 643: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/643.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundaclosingcurlybracketisnotcorrect.
Aclosingcurlybracketshouldalwaysbefollowedbyasinglespace,unlessitisthelastcharacterontheline,orunlessitisfollowedbyaclosingparenthesis,acomma,orasemicolon.
Aclosingcurlybracketmustalwaysbeprecededbyasinglespace,unlessitisthefirstcharacterontheline.
![Page 644: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/644.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundtheclosingcurlybracketfollowstheruledescribedabove.
![Page 645: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/645.jpg)
TypeName OpeningGenericBracketsMustBeSpacedCorrectly
CheckId SA1014
Category SpacingRules
![Page 646: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/646.jpg)
CauseAnopeninggenericbracketwithinaC#elementisnotspacedcorrectly.
![Page 647: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/647.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundanopeninggenericbracketisnotcorrect.
Anopeninggenericbracketshouldneverbeprecededorfollowedbywhitespace,unlessthebracketisthefirstorlastcharacterontheline.
![Page 648: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/648.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespaceoneithersideoftheopeninggenericbracket.
![Page 649: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/649.jpg)
TypeName ClosingGenericBracketsMustBeSpacedCorrectly
CheckId SA1015
Category SpacingRules
![Page 650: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/650.jpg)
CauseAclosinggenericbracketwithinaC#elementisnotspacedcorrectly.
![Page 651: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/651.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundaclosinggenericbracketisnotcorrect.
Aclosinggenericbracketshouldneverbeprecededbywhitespace,unlessthebracketisthefirstcharacterontheline.
![Page 652: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/652.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespacebeforetheclosinggenericbracket.
![Page 653: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/653.jpg)
TypeName OpeningAttributeBracketsMustBeSpacedCorrectly
CheckId SA1016
Category SpacingRules
![Page 654: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/654.jpg)
CauseAnopeningattributebracketwithinaC#elementisnotspacedcorrectly.
![Page 655: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/655.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundanopeningattributebracketisnotcorrect.
Anopeningattributebracketshouldneverbefollowedbywhitespace,unlessthebracketisthelastcharacterontheline.
![Page 656: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/656.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespaceaftertheopeningattributebracket.
![Page 657: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/657.jpg)
TypeName ClosingAttributeBracketsMustBeSpacedCorrectly
CheckId SA1017
Category SpacingRules
![Page 658: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/658.jpg)
CauseAclosingattributebracketwithinaC#elementisnotspacedcorrectly.
![Page 659: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/659.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundaclosingattributebracketisnotcorrect.
Aclosingattributebracketshouldneverbeprecededbywhitespace,unlessthebracketisthefirstcharacterontheline.
![Page 660: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/660.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespacebeforetheclosingattributebracket.
![Page 661: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/661.jpg)
TypeName NullableTypeSymbolsMustNotBePrecededBySpace
CheckId SA1018
Category SpacingRules
![Page 662: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/662.jpg)
CauseAnullabletypesymbolwithinaC#elementisnotspacedcorrectly.
![Page 663: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/663.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundanullabletypesymbolisnotcorrect.
Anullabletypesymbolshouldneverbeprecededbywhitespace,unlessthesymbolisthefirstcharacterontheline.
![Page 664: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/664.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespacebeforethenullabletypesymbol.
![Page 665: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/665.jpg)
TypeName MemberAccessSymbolsMustBeSpacedCorrectly
CheckId SA1019
Category SpacingRules
![Page 666: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/666.jpg)
CauseThespacingaroundamemberaccesssymbolisincorrect,withinaC#codefile.
![Page 667: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/667.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundamemberaccesssymbolisincorrect.Amemberaccesssymbolshouldnothavewhitespaceoneitherside,unlessitisthefirstcharacterontheline.
![Page 668: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/668.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthememberaccesssymbolisnotsurroundedbyanywhitespace.
![Page 669: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/669.jpg)
TypeName IncrementDecrementSymbolsMustBeSpacedCorrectly
CheckId SA1020
Category SpacingRules
![Page 670: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/670.jpg)
CauseAnincrementordecrementsymbolwithinaC#elementisnotspacedcorrectly.
![Page 671: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/671.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundanincrementordecrementsymbolisnotcorrect.
Thereshouldbenowhitespacebetweentheincrementordecrementsymbolandtheitemthatisbeingincrementedordecremented.
![Page 672: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/672.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthereisnowhitespacebetweentheincrementordecrementsymbolandtheitemthatisbeingincrementedordecremented.
![Page 673: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/673.jpg)
TypeName NegativeSignsMustBeSpacedCorrectly
CheckId SA1021
Category SpacingRules
![Page 674: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/674.jpg)
CauseAnegativesignwithinaC#elementisnotspacedcorrectly.
![Page 675: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/675.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundanegativesignisnotcorrect.
Anegativesignshouldalwaysbeprecededbyasinglespace,unlessitcomesafteranopeningsquarebracket,aparenthesis,oristhefirstcharacterontheline.
Anegativesignshouldneverbefollowedbywhitespace,andshouldneverbethelastcharacteronaline.
![Page 676: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/676.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundthenegativesignfollowstheruledescribedabove.
![Page 677: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/677.jpg)
TypeName PositiveSignsMustBeSpacedCorrectly
CheckId SA1022
Category SpacingRules
![Page 678: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/678.jpg)
CauseApositivesignwithinaC#elementisnotspacedcorrectly.
![Page 679: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/679.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundapositivesignisnotcorrect.
Apositivesignshouldalwaysbeprecededbyasinglespace,unlessitcomesafteranopeningsquarebracket,aparenthesis,oristhefirstcharacterontheline.
Apositivesignshouldneverbefollowedbywhitespace,andshouldneverbethelastcharacteronaline.>
![Page 680: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/680.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundthepositivesignfollowstheruledescribedabove.
![Page 681: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/681.jpg)
TypeName DereferenceAndAccessOfMustBeSpacedCorrectly
CheckId SA1023
Category SpacingRules
![Page 682: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/682.jpg)
CauseAdereferencesymboloranaccess-ofsymbolwithinaC#elementisnotspacedcorrectly.
![Page 683: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/683.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundadereferenceoraccess-ofsymbolisnotcorrect.
Thespacingaroundthesymboldependsuponwhetherthesymbolisusedwithinatypedeclaration.Ifso,thesymbolmustalwaysbefollowedbyasinglespace,unlessitisthelastcharacterontheline,orisfollowedbyanopeningsquarebracketoraparenthesis.Inaddition,thesymbolshouldnotbeprecededbywhitespace,andshouldnotbethefirstcharacterontheline.Anexampleofaproperlyspaceddereferencesymbolusedwithinatypedeclarationis:
object*x=null;
Whenadereferenceoraccess-ofsymbolisusedoutsideofatypedeclaration,theoppositeruleapplies.Inthiscase,thesymbolmustalwaysbeprecededbyasinglespace,unlessitisthefirstcharacterontheline,orisprecededbyanopeningsquarebracketoraparenthesis.Thesymbolshouldnotbefollowedbywhitespace,andshouldnotbethelastcharacterontheline.Forexample:
y=*x;
![Page 684: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/684.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundthedereferenceoraddress-ofsymbolfollowstheruledescribedabove.
![Page 685: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/685.jpg)
TypeName ColonsMustBeSpacedCorrectly
CheckId SA1024
Category SpacingRules
![Page 686: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/686.jpg)
CauseAcolonwithinaC#elementisnotspacedcorrectly.
![Page 687: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/687.jpg)
RuleDescriptionAviolationofthisruleoccurswhenthespacingaroundacolonisnotcorrect.
Thespacingaroundacolondependsuponthetypeofcolonandhowitisusedwithinthecode.Acolonappearingwithinanelementdeclarationmustalwayshaveasinglespaceoneitherside,unlessitisthefirstorlastcharacterontheline.Forexampleallofthecolonsbelowfollowthisrule:
publicclassClass2<T>:Class1whereT:MyType
{
publicClass2(intx):base(x)
{
}
}
Whenthecoloncomesattheendofalabelorcasestatement,itmustalwaysbefollowedbywhitespaceorbethelastcharacterontheline,butshouldneverbeprecededbywhitespace.Forexample:
_label:
switch(x)
{
case2:
returnx;
}
Finally,whenacolonisusedwithinaconditionalstatement,itmustalwayscontainasinglespaceoneitherside,unlessthecolonisthefirstorlastcharacterontheline.Forexample:
![Page 688: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/688.jpg)
intx=y?2:3;
![Page 689: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/689.jpg)
HowtoFixViolationsTofixaviolationofthisrule,ensurethatthespacingaroundthecolonfollowstheruledescribedabove.
![Page 690: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/690.jpg)
TypeName CodeMustNotContainMultipleWhitespaceInARow
CheckId SA1025
Category SpacingRules
![Page 691: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/691.jpg)
CauseThecodecontainsmultiplewhitespacecharactersinarow.
![Page 692: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/692.jpg)
RuleDescriptionAviolationofthisruleoccurswheneverthecodecontainsmultiplewhitespacecharactersinarow,unlessthecharacterscomeatthebeginningorendofalineofcode,orcomeafteracommaorsemicolon.
![Page 693: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/693.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removetheextrawhitespacecharactersareleaveonlyasinglespace.
![Page 694: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/694.jpg)
TypeName CodeMustNotContainSpaceAfterNewKeywordInImplicitlyTypedArrayAllocation
CheckId SA1026
Category SpacingRules
![Page 695: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/695.jpg)
CauseAnimplicitlytypednewarrayallocationwithinaC#codefileisnotspacedcorrectly.
![Page 696: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/696.jpg)
RuleDescriptionAviolationofthisruleoccurswheneverthecodecontainsanimplicitlytypednewarrayallocationwhichisnotspacedcorrectly.Withinanimplicitlytypednewarrayallocation,thereshouldnotbeanyspacebetweenthenewkeywordandtheopeningarraybracket.Forexample:
vara=new[]{1,10,100,1000};
![Page 697: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/697.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removeanywhitespacebetweenthenewkeywordandtheopeningarraybracket.
![Page 698: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/698.jpg)
TypeName TabsMustNotBeUsed
CheckId SA1027
Category SpacingRules
![Page 699: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/699.jpg)
CauseTheC#codecontainsatabcharacter.
![Page 700: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/700.jpg)
RuleDescriptionAviolationofthisruleoccurswheneverthecodecontainsatabcharacter.
TabsshouldnotbeusedwithinC#code,becausethelengthofthetabcharactercanvarydependingupontheeditorbeingusedtoviewthecode.Thiscancausethespacingandindexingofthecodetovaryfromthedeveloper’soriginalintention,andcaninsomecasesmakethecodedifficulttoread.
Forthesereasons,tabsshouldnotbeused,andeachlevelofindentationshouldconsistoffourspaces.Thiswillensurethatthecodelooksthesamenomatterwhicheditorisbeingusedtoviewthecode.
![Page 701: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/701.jpg)
HowtoFixViolationsTofixaviolationofthisrule,removethetabcharacterfromthecode.
![Page 702: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/702.jpg)
StartingwithStyleCop4.3.2,itispossibletosuppressthereportingofruleviolationsbyaddingsuppressionattributeswithinthesourcecode.ThesyntaxforthesesuppressionsissimilartothatforVisualStudioCodeAnalysis,orFxCop.FormoreinformationaboutCodeAnalysissuppressions,seethefollowingarticle:InSourceSuppressionsOverview.
StyleCoprulesuppressionsareregisteredincodeusingtheSuppressMessageattribute.TheSuppressMessageattributeisaconditionalattribute,whichisincludedintheILmetadataofyourmanagedcodeassemblyonlyiftheCODE_ANALYSIScompilationsymbolisdefinedatcompiletime.
Werecommendusingin-sourcesuppressionsondebugbuilds,inordertoeliminatethepossibilityofmistakenlyshippingthein-sourcesuppressionmetadataandcompromisingexecutionorperformancebecauseofthemetadatabloat.
TheSuppressMessageattributehasthefollowingformat:
[SuppressMessage("RuleCategory,"RuleId","Justification")]
Where:
RuleCategory-TheStyleCoprulenamespaceinwhichtheruleisdefined.Forexample,StyleCop.CSharp.DocumentationRulesRuleId-Theidentifierfortherule,usingtheformatshortname:longname.Forexample,SA1600:ElementsMustBeDocumentedJustification-Thetextthatisusedtodocumentthereasonforsuppressingthemessage.
TheSuppressMessageattributealsotakesthefollowingoptionalparameters.TheseparametersarecompletelyignoredbyStyleCopanddonotneedtobefilledinforStyleCopsuppressions.
MessageIdScopeTarget
SuppressMessageUsage
StyleCopviolationsaresuppressedattheleveltowhichaninstanceofthe
![Page 703: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/703.jpg)
SuppressMessageattributeisapplied.Thepurposeofthisistotightlycouplethesuppressioninformationtothecodewheretheviolationoccurs.
Forexample,aStyleCopSuppressMessageattributeplacedonaclasswillsuppresstheruleforallcontentsoftheclass.Thesameattributeplacedonamethodwillonlysuppresstherulewithinthemethod.
GlobalSuppressions
StyleCopdoesnotsupportthenotionofglobalsuppressionsorfile-levelsuppressions.Suppressionsmustbeplacedonacodeelement.
Examples:
ThefollowingcodesuppressestheElementsMustBeDocumentedruleforthegivenclassandallitscontents:
[SuppressMessage("StyleCop.CSharp.DocumentationRules","SA1600:ElementsMustBeDocumented")]
publicclassMyUndocumentedClass
{
publicvoidMyUndocumentedMethod
{
}
}BeginningwithStyleCop4.4.0,itisalsopossibletosuppressalloftheruleswithinarulenamespace,usingasinglesuppressionattribute.ThisisindicatedbyreplacingtheruleCheckIDandrulenamewithasingleasterisk.ThefollowingcodeexamplesuppressesallofStyleCop'sdefaultdocumentationruleswithintheinnerclass.Inthiscase,StyleCopwouldstillflagaviolationindicatingthattheouterclassismissingdocumentation,butitwouldignorealldocumentationrulesfortheinnerclassanditscontents.
publicclassOuterClass
![Page 704: The StyleCop tool provides warnings ... - Documentation & Help · Documentation Rules (SA1600-) Rules which verify the content and formatting of code documentation. Layout Rules (SA1500-)](https://reader033.fdocuments.us/reader033/viewer/2022061523/5fc9c6be34294d7640473a3f/html5/thumbnails/704.jpg)
{
[SuppressMessage("StyleCop.CSharp.DocumentationRules","*")]
publicclassInnerClass
{
publicvoidMyUndocumentedMethod
{
}
}}