Skip to content

Add IMethodGroupReferenceOperation #76620

@MarkKharitonov

Description

@MarkKharitonov

Background and Motivation

Please, see #76616.

Consider the following source code:

public class Type1
{
    public static void f(){}
}

using static Type1;
using Type3 = Type1;
public class Type2
{
    public static string X = nameof(f);
    public static string Y = nameof(Type1.f);
    public static string Z = nameof(Type3.f);
}

It demonstrates three different way to express the same nameof semantics. An important detail - the argument of nameof is a method group:

  1. Type1.f - fully qualified through its parent type Type1
  2. Type3.f - fully qualified through an alias Type3
  3. f - unqualified, imported into the scope by the using static Type1 directive.

Inspecting the INameOfOperation yields different results for the third case as explained in great detail in the aforementioned issue.

Proposed API

Seems like the only case that needs special attention is when the argument of the nameof operator is a method group. Hence the idea is to introduce something like IMethodGroupReferenceOperation:

namespace Microsoft.CodeAnalysis.Operations
{
     public class IMethodGroupReferenceOperation
     {
         public INamedTypeSymbol ContainingType { get; }
         public string Name { get; }
     }
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.Feature Requestapi-needs-workAPI needs work before it is approved, it is NOT ready for implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions