-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect 'Use nameof' within nested types #229
Comments
Here is the fix for REFL014 making the same mistake. Before: using System.Reflection;
class Base
{
protected bool M { get; }
}
class Derived : Base
{
class Nested
{
void M()
{
// REFL014 Prefer typeof(Base).GetProperty(nameof(Base.M), BindingFlags.NonPublic |
// BindingFlags.Instance | BindingFlags.DeclaredOnly).GetMethod.
// ↓↓↓↓↓↓↓↓↓
typeof(Base).GetMethod("get_M", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
}
}
} After: using System.Reflection;
class Base
{
protected bool M { get; }
}
class Derived : Base
{
class Nested
{
void M()
{
// CS1540 Cannot access protected member 'Base.M' via a qualifier of type 'Base';
// the qualifier must be of type 'Derived.Nested' (or derived from it)
// ↓
typeof(Base).GetProperty(nameof(Base.M), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly).GetMethod;
}
}
} |
Hmm, it is somewhat annoying that we already have a check |
The fix in the first post should be |
I still repro this in |
This affects REFL016 and the fixes for others like REFL014.
There should be no warning here:
Result:
The text was updated successfully, but these errors were encountered: