-
Notifications
You must be signed in to change notification settings - Fork 22
SA1649
TypeName |
FileHeaderFileNameDocumentationMustMatchTypeName |
CheckId |
SA1649 |
Category |
Documentation Rules |
The file tag within the file header at the top of a C# code file does not match the first type declared in the file. For generics that are defined as Class1<T> the name of the file needs to be Class1{T}.cs and this should appear in the header also. Partial classes are ignored.
A violation of this rule occurs when the file tag within the file header at the top of a C# file does not contain the name of the first type in the file. For example, consider a C# source file named Class1.cs, with the following header:
//-----------------------------------------------------------------------
// <copyright file="ThisIsNotTheCorrectTypeName.cs" company="My Company">
// Custom company copyright tag.
// </copyright>
//-----------------------------------------------------------------------
public class Class1
{
}
A violation of this rule would occur, since the file tag does not contain the correct name of the first type in the file. The header should be written as:
//-----------------------------------------------------------------------
// <copyright file="Class1.cs" company="My Company">
// Custom company copyright tag.
// </copyright>
//-----------------------------------------------------------------------
public class Class1
{
}
<P>A generic class should be written as:</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">//-----------------------------------------------------------------------</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">// <copyright file="Class1{T}.cs" company="My Company"></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">//<SPAN style="mso-spacerun: yes"> </SPAN>Custom company copyright tag.</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">// </copyright></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">//-----------------------------------------------------------------------</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes"><SPAN style="mso-spacerun: yes"> </SPAN><SPAN style="COLOR: blue">public</SPAN>
<SPAN style="COLOR: blue">class</SPAN>
<SPAN style="COLOR: #2b91af">Class1</SPAN><SPAN style="COLOR: #000000"><T></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes"><SPAN style="mso-spacerun: yes"> </SPAN>{</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none">
</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes"><SPAN style="mso-spacerun: yes"> </SPAN>}</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-vertical-align-alt: auto; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-no-proof: yes"></SPAN></P>
<P></P>
<H2>How to Fix Violations</H2>
<P>To fix a violation of this rule, add the name of the first type from the file to the file tag.</P>
<h2>How to Suppress Violations</h2>
<pre>[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:FileHeaderFileNameDocumentationMustMatchTypeName", Justification = "Reviewed.")]</pre>
</div></div>
</body>
- - SA0102 - Clean Install
- - Download
- - Documentation Rules - Layout Rules - Maintainability Rules - Naming Rules - Ordering Rules - Readability Rules - Spacing Rules - Suppressions
- - Adding a custom StyleCop settings page - Adding custom rule settings - Authoring a custom styleCop rule - Authoring rules metadata - Custom CSharp Language Service - Custom MSBuild Integration - Hosting StyleCop in a Custom Environment - Installing a Custom Rule - Integrating StyleCop Into Build Environments - Integrating StyleCop into MSBuild - Writing Custom Rules for StyleCop