重写 lambda 扩展方法
我创建了一个扩展方法,它的工作原理就像我想要的那样。我注意到,party
和 property
参数以某种方式被“复制”到 lambda 表达式中。这样我就不需要维护编辑器/政党/属性关联的自定义列表。
但是,我需要重置 ButtonEdit 的 ButtonClick 事件。由于这是匿名的,我也无法使用 -= 运算符。
所以,我的问题是 - 如何重写这个方法以便可以删除委托?或者,我可以使用哪种其他方法来处理具有额外参数(例如 party
和 property
)的特定事件处理程序?
private static void SetupAddressButtonClickEvent(this ButtonEdit editor, Party party, string property)
{
editor.SetAddressDisplayText(party, property);
editor.ButtonClick += (sender, e) =>
{
party.ShowAddressLookupDialog(property);
editor.SetAddressDisplayText(party, property);
};
}
谢谢你, 斯特凡
I've created an extension method that works just like I wanted. I've noticed that somehow the party
and property
parameters are 'copied' into the lambda expression. This way I do not need to maintain a custom list of editor/party/property associations.
However, I need to reset the ButtonEdit's ButtonClick event. Since this one is anonymous I cannot use the -= opertor either.
So, my question is - how do I rewrite this method so that the delegate can be removed? Or, which other approach can I use to handle a specific event handler with extra parameters (such as party
and property
)?
private static void SetupAddressButtonClickEvent(this ButtonEdit editor, Party party, string property)
{
editor.SetAddressDisplayText(party, property);
editor.ButtonClick += (sender, e) =>
{
party.ShowAddressLookupDialog(property);
editor.SetAddressDisplayText(party, property);
};
}
Thank you,
Stefan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑选项 2 可以是:
然后像这样使用它:
我不确定这会对您有多大帮助,因为我不 100% 理解您要解决的问题。
edit option 2 could be:
and then use it like this:
I'm not sure how much this will help you because I don't 100% understand what you're trying to solve.