| Topic | Value |
|---|---|
| Id | REFL017 |
| Severity | Warning |
| Enabled | True |
| Category | ReflectionAnalyzers.SystemReflection |
| Code | GetXAnalyzer |
Don't use name of wrong member.
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.
Use the code fix.
Configure the severity per project, for more info see MSDN.
#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 memberOr put this at the top of the file to disable all instances.
#pragma warning disable REFL017 // Don't use name of wrong member[System.Diagnostics.CodeAnalysis.SuppressMessage("ReflectionAnalyzers.SystemReflection",
"REFL017:Don't use name of wrong member",
Justification = "Reason...")]