我认为我的大脑已经变得油腻,因为我正在努力做一些简单的事情.在我的应用程序中,我有以下代码来配置Nhibernate(我的问题不是特定于Nhibernate).
return Fluently.Configure()
.ExposeConfiguration(c => {
c.EventListeners.PostInsertEventListeners = new IPostInsertEventListener[] { new LoggingEventListener() };
c.EventListeners.PostUpdateEventListeners = new IPostUpdateEventListener[] { new LoggingEventListener() };
});
Run Code Online (Sandbox Code Playgroud)
但是我需要将配置(ExposeConfiguration中的内容)存储在私有变量中.我可以做以下事情:
return Fluently.Configure()
.ExposeConfiguration(c => _configuration = c);
Run Code Online (Sandbox Code Playgroud)
_configuration是一个私有变量.但这并没有添加我的额外配置选项(EventListeners的东西).我玩各种各样的东西,但我想我的lambda知识不如我想的那么好.
我很感激你的帮助.谢谢
Col*_*kay 66
lambda表达式只是一个经常映射到其中一个Func<T1, T2, ..., TResult>变体的委托.
Func<T1, TResult> myVar = c => _configuration = c;
Run Code Online (Sandbox Code Playgroud)
替换TResult并T1与相关类型.
这可能对你有用.
| 归档时间: |
|
| 查看次数: |
31094 次 |
| 最近记录: |