Skip to content

using-placement

C#styleno fixdefault: offcsharp/stylecop

Reports a using directive outside the namespace declaration in a file that has one. No fix: moving a directive changes how names are looked up.

A using inside the namespace is resolved relative to it, and one outside is global to the file. Projects choose one place for all files, so that the lookup of names does not depend on which file a directive is in.

Reported
using System;
namespace N
{
using System.IO;
...
csharp:
lint:
rules:
using-placement: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line using-placement in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1200 full