Skip to content

Latest commit

 

History

History
64 lines (48 loc) · 1.8 KB

File metadata and controls

64 lines (48 loc) · 1.8 KB

REFL017

Don't use name of wrong member

Topic Value
Id REFL017
Severity Warning
Enabled True
Category ReflectionAnalyzers.SystemReflection
Code GetXAnalyzer

Description

Don't use name of wrong member.

Motivation

public class Foo
{
    public Foo()
    {
        var member = typeof(AggregateException).GetProperty(nameof(this.InnerExceptionCount), 
            BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
    }

    public int InnerExceptionCount => 0;
}

In the above example we are getting the private property AggregateException.InnerExceptionCount but using nameof(this.InnerExceptionCount) to get the name. This rule checks that the same member is used.

How to fix violations

Use the code fix.

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable REFL017 // Don't use name of wrong member
Code violating the rule here
#pragma warning restore REFL017 // Don't use name of wrong member

Or put this at the top of the file to disable all instances.

#pragma warning disable REFL017 // Don't use name of wrong member

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("ReflectionAnalyzers.SystemReflection", 
    "REFL017:Don't use name of wrong member", 
    Justification = "Reason...")]