Hi everyone! Today I want to talk about closures and extracting their values from lamda expression.

This article is the second version of the article in my blog. So, let’s get it started.

The problem

One of my project has a lot of Action and Func delegates as parameters for methods. It has them everywhere and I got a task to write some unit-tests for some of these methods. Let’s imagine that there is a method that take Action like a parameter.

The delegate can be initialized with lambda expression.

So, we call them in a way like in a snippet below.

Because I was writing unit-tests I had to get some values from Action for Asserts . But It tended to be a real problem, because I couldn’t use Expression , because of some historical reasons.