-
Notifications
You must be signed in to change notification settings - Fork 23
SA1024
TypeName |
ColonsMustBeSpacedCorrectly |
CheckId |
SA1024 |
Category |
Spacing Rules |
A colon within a C# element is not spaced correctly.
A violation of this rule occurs when the spacing around a colon is not correct.
The spacing around a colon depends upon the type of colon and how it is used within the code. A colon appearing within an element declaration must always have a single space on either side, unless it is the first or last character on the line. For example all of the colons below follow this rule:
public class Class2<T> : Class1 where T : MyType
{
public Class2(int x) : base(x)
{
}
}
When the colon comes at the end of a label or case statement, it must always be followed by whitespace or be the last character on the line, but should never be preceded by whitespace. For example:
_label:
switch (x)
{
case 2:
return x;
}
Finally, when a colon is used within a conditional statement, it must always contain a single space on either side, unless the colon is the first or last character on the line. For example:
int x = y ? 2 : 3;
To fix a violation of this rule, ensure that the spacing around the colon follows the rule described above.
[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1024:ColonsMustBeSpacedCorrectly", Justification = "Reviewed.")]
- - 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