roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

`this` is not recommended inside `nameof` in an attribute argument context

Open Rekkonnect opened this issue 9 months ago • 1 comments

Version Used

Visual Studio Version 17.14.5 Roslyn 4.14.0-3.25279.5 @ 995f12b60535afe75cafbcefada9161d8dc4f31f

Steps to Reproduce

Paste the following code anywhere applicable and place the cursor in the $$ position:

public class Example
{
    private string _field;

    [MemberNotNull(nameof($$))]
    public void Method()
    {
    }
}

Start typing this.

Expected result

this is recommended.

Actual result

this is not recommended.

Note, typing this. and then starting to type _field properly recommends the field.

Rekkonnect avatar Jun 14 '25 18:06 Rekkonnect

This doesn't seem related, but it's such a coincidence that I'll point to it anyway: https://github.com/dotnet/roslyn/issues/78983

jnm2 avatar Jun 16 '25 00:06 jnm2

Hi @CyrusNajmabadi 👋 I’d like to work on this issue (#78979). It seems that inside an attribute like [MemberNotNull(nameof($$))], this. isn’t being suggested and the IDE shows “this is not recommended”—which isn't accurate. I'd like to explore the completion provider logic and adjust it so that this. is appropriately recommended in this context. Please let me know if there are existing tests to update or a preferred approach to proceed.

Subham-KRLX avatar Jul 02 '25 05:07 Subham-KRLX

Sure. Look for the ThisKeywordRecomender and the corresponding ThisKeywordRecomenderTests.

Thanks!

CyrusNajmabadi avatar Jul 02 '25 05:07 CyrusNajmabadi