Skip to content

"Use null propagation" doesn't show up for compound assignments #81322

@jnm2

Description

@jnm2

Version Used: Insiders [11206.111]

No fix is offered on the if like it is if the assignment is changed to simple assignment:

class C
{
    event System.Action SomeEvent;

    static void M(C c)
    {
        if (c is not null)
            c.SomeEvent += () => { };
    }
}

Expected fix:

class C
{
    event System.Action SomeEvent;

    static void M(C c)
    {
        c?.SomeEvent += () => { };
    }
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions