Maybe it's just me, but I really don't see the point in this. To accomplish what you are trying to do, you do not need to write all this.
Example code in a console application:
class Program { static void Main(string[] args) { var temp = Execute(DoSomething); Console.Write(temp); Console.Read(); } static int Execute(Func<int> methodToRun) { return methodToRun.Invoke(); } static int DoSomething() { return 1; } }
As you can see, this gives you the same results in a more concise and clean way. I think that you were absent, so that Action
, Action<>
and Func<>
are all syntactic sugar for the delegate
, so there is no need to mix 2 syntaxes and no need to restore the whole expression as you do.
Matteo mosca
source share