Is there any way to invoke an extension method on a method, but without a explicit reference?
For example, if I have a extension method:
public static class Extensions {
public static void FooOn(this Func<string> method) =>
Console.WriteLine($"Foo on {method()}");
}
I thought maybe I could do something like this, but perhaps not.
class Program {
private string Bar() => "you";
void Main() => Bar.FooOn(); // won't compile
}
Instead it seems I have to declare a temporary reference:
class Program {
private string Bar() => "you";
void Main(){
Func<string> temp = Bar;
temp.FooOn();
}
}
So is there any way to invoke an extension method on a method, but without a explicit reference?