Skip to content

qualify-instance-members

C#stylefix: safedefault: offcsharp/stylecop

Reports a field, property, method or event of the containing type that is used by its simple name. The fix writes this. before it.

With this. it is clear at a glance that the name is a member and not a local, a parameter or a static, so a reader does not scroll up to see where a name comes from. It is a style that some projects choose and others do not.

Reported
...
{
int x;
static int s;
int M() => x + s;
int N() => this.x;
void P(int x) { x = 1; M(); }
}
After the fix
...
{
int x;
static int s;
int M() => this.x + s;
int N() => this.x;
void P(int x) { x = 1; this.M(); }
}
csharp:
lint:
rules:
qualify-instance-members: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line qualify-instance-members 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 SA1101 full