I think my brain has become fried as i'm struggling to do something simple. In my application i have the following code to configure Nhibernate (my issue is not specific to Nhibernate).
return Fluently.Configure() .ExposeConfiguration(c => { c.EventListeners.PostInsertEventListeners = new IPostInsertEventListener[] { new LoggingEventListener() }; c.EventListeners.PostUpdateEventListeners = new IPostUpdateEventListener[] { new LoggingEventListener() }; });
However I need to store the configuration (the stuff inside ExposeConfiguration) inside a private variable. I can do the following:
return Fluently.Configure() .ExposeConfiguration(c => _configuration = c);
Where _configuration is a private variable. But this doesn't add my extra configuration options (the EventListeners stuff). I've played around with various things but i guess my lambda knowledge isn't as good as i thought.
I'd appreciate your help. Thanks
Lambda expressions can use variables defined in an outer scope. We refer to these lambdas as capturing lambdas. They can capture static variables, instance variables, and local variables, but only local variables must be final or effectively final.
A lambda expression can't define any new scope as an anonymous inner class does, so we can't declare a local variable with the same which is already declared in the enclosing scope of a lambda expression. Inside lambda expression, we can't assign any value to some local variable declared outside the lambda expression.
To create a lambda expression, you specify input parameters (if any) on the left side of the lambda operator and an expression or a statement block on the other side. When you use method-based syntax to call the Enumerable. Select method in the System.
Creating a Lambda Expression in C++auto greet = []() { // lambda function body }; Here, [] is called the lambda introducer which denotes the start of the lambda expression. () is called the parameter list which is similar to the () operator of a normal function.
A lambda expression is just a delegate that often maps to one of the Func<T1, T2, ..., TResult>
variants.
Func<T1, TResult> myVar = c => _configuration = c;
Replacing TResult
and T1
with the relevant types.
That might work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With