What I really wanted was something like the block statement in Ruby, where I just pass in arbitrary code to a method that would then execute it. It was a little trickier in C# because of the variations in the method signture. A method that had a Func parameter wouldn’t work because I had varying number of parameters. Also the changing return value added a nice twist. In the end, it came out rather nice.
With this little method I can now pass in any method and
Here are a few tests to show what it looks like.
That’s not quite as clean a block parameter in Ruby, but I can live with it for now.