Table of Contents

SA1217: Using static directives should be ordered alphabetically

📝 This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic.

Cause

The using static directives within a C# code file are not sorted alphabetically by full type name.

Rule description

A violation of this rule occurs when the using static directives are not sorted alphabetically by full type name. Sorting the using static directives alphabetically makes the code cleaner and easier to read.

By default, using static directives for types in the System namespace precede all other using static directives, the same way SA1210 orders System namespaces first. For example, using static System.Math; should be placed before using static Absolutes.Constants;. To sort all using static directives together alphabetically instead, set systemUsingDirectivesFirst to false (see Configuration.md).

Global using directives (C# 10) are analyzed independently from local using directives. Diagnostics and fixes compare only directives which both use, or both omit, the global modifier.

How to fix violations

To fix an instance of this violation, order the using static directives alphabetically by full type name.

How to suppress violations

#pragma warning disable SA1217 // Using static directives should be ordered alphabetically
using static System.Math;
#pragma warning restore SA1217 // Using static directives should be ordered alphabetically