有没有办法在.Net 3.5中用委托来做到这一点? [英] Is there a way to do this with delegates in .Net 3.5?
问题描述
我们有一个系统,需要动态更改一组步骤结束时发生的情况.我们正在使用委托进行此操作.但是,我们需要在步骤集末尾调用的方法具有不同的签名.目前,我们可以选择使用标准委托人签名(可能是从ASP.Net复制事件处理程序)来执行此操作,还是以其他方式来执行此操作(确定!).有没有办法在.Net 3.5中用委托来做到这一点?还是我们可以使用C#4.0的命名参数或委托中的可选参数来做到这一点?
我们通过使用事件处理程序方法签名来解决此问题,即我们的委托期望(对象发送者,eventargs e),并构建了一个自定义事件args类./p>
We have a system where we need to dynamically change what happens at the end of a set of steps. We're doing this using a delegate. However the methods that we need to call at the end of the set of steps have different signatures. We have a choice at the moment to either do this using a standard delegate signature (probably copying the event handler one from ASP.Net) or doing it some other way (undertermined!) Is there a way to do this with delegates in .Net 3.5 ? Or could we do this using C# 4.0's named parameters or optional parameters on the delegate?
We got around this by using the event handler method signature, i.e. our delegate expects (object sender, eventargs e) and we built a custom event args class.
这篇关于有没有办法在.Net 3.5中用委托来做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!