TypeName

AllAccessorsMustBeSingleLineOrMultiLine

CheckId

SA1504

Category

Layout Rules

Cause

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.

Rule Description

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;

        }

    }

 

How to Fix Violations

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.