-
Notifications
You must be signed in to change notification settings - Fork 22
SA1504
TypeName |
AllAccessorsMustBeSingleLineOrMultiLine |
CheckId |
SA1504 |
Category |
Layout Rules |
Within a C# property, indexer or event, at least one of the child accessors is written on a single line, and at least one of the child accessors is written across multiple lines.
A violation of this rule occurs when the accessors within a property, indexer or event are not consistently written on a single line or on multiple lines. This rule is intended to increase the readability of the code by requiring all of the accessors within an element to be formatted in the same way.
For example, the following property would generate a violation of this rule, because one accessor is written on a single line while the other accessor snaps multiple lines.
public bool Enabled
{
get { return this.enabled; }
set
{
this.enabled = value;
}
}
The violation can be avoided by placing both accessors on a single line, or expanding both accessors across multiple lines:
public bool Enabled
{
get { return this.enabled; }
set { this.enabled = value; }
}
public bool Enabled
{
get
{
return this.enabled;
}
set
{
this.enabled = value;
}
}
To fix a violation of this rule, write each accessor on a single line if the accessors are short, or expand both accessors across multiple lines if the accessors are longer.
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1504:AllAccessorsMustBeSingleLineOrMultiLine", 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