Skip to content

Incorrect 'Use nameof' within nested types #229

Open
@jnm2

Description

@jnm2

This affects REFL016 and the fixes for others like REFL014.

There should be no warning here:

class Base
{
    protected void M() { }
}

class Derived : Base
{
    class Nested
    {
        void M()
        {
            // REFL016 Use nameof. ↓↓↓
            typeof(Base).GetMethod("M");
        }
    }
}

Result:

class Base
{
    protected void M() { }
}

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).GetMethod(nameof(Base.M));
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions