Skip to content

[Proposal] Allow extension methods affect choice of type in method groups and formattable strings #173

@ashmind

Description

@ashmind

Problem

Let's say I have the following extension method:

public Func<T2, TResult> Curry<T1, T2, TResult>(this Action<T1, T2, TResult> action, T1 arg) {}

and the following class method:

public static int Add(int x1, int x2);

If I call this extension method as a normal method, it looks like this:

Curry(Add, 5);

However as an extension method, it would look like this:

((Action<int, int>)Add).Curry(5);

Another related problem is with interpolated strings -- since extension methods do not affect type choice, it is not possible to call IFormattable extension methods on $"".

Potential solution

I suggest allowing extension methods to influence the type choice for the method group.
Example:

Add.Curry(5);

Similar logic should apply to $"".

Pros
  1. Consistency between different call types
  2. Reduced verbosity in functional scenarios (e.g. Select(Add.Curry(5)))
  3. Allows extension methods on FormattableString
Cons
  1. Resolution is pretty complex as it is, not sure if there are any edge cases that would complicate this further

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions