Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 1.76 KB

File metadata and controls

61 lines (46 loc) · 1.76 KB

SA1204

TypeName SA1204StaticElementsMustAppearBeforeInstanceElements
CheckId SA1204
Category Ordering Rules

Cause

A static element is positioned beneath an instance element of the same type.

Rule description

A violation of this rule occurs when a static element is positioned beneath an instance element of the same type. All static elements should be placed above all instance elements of the same type to make it easier to see the interface exposed from the instance and static version of the class.

This rule applies to classes, structs, and interfaces. Static interface members (introduced with C# 8 default interface members) must appear before instance members, including members that provide default implementations.

For example, the following interface declaration violates this rule because the static member appears after an instance member with a default implementation:

public interface IExample
{
    void Instance() { }
    static void Helper() { } // SA1204
}

A compliant ordering places static interface members before instance members:

public interface IExample
{
    static void Helper() { }
    void Instance() { }
}

How to fix violations

To fix an instance of this violation, place all static elements above all instance elements of the same type.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:StaticElementsMustAppearBeforeInstanceElements", Justification = "Reviewed.")]
#pragma warning disable SA1204 // StaticElementsMustAppearBeforeInstanceElements
#pragma warning restore SA1204 // StaticElementsMustAppearBeforeInstanceElements