我接管了一个基于Prism的C#应用程序,该应用程序包含相当多的lambda式一行程序,如下所示:
using Prism.Interactivity.InteractionRequest;
...
public InteractionRequest<Confirmation> OwnObjectRequest { get; } = new InteractionRequest<Confirmation>();
...
OwnObjectRequest.Raise(confirmation, c => // one-liner
{
Confirmation conf = (Confirmation)c;
if (conf.Confirmed)
{
DoSomething();
}
});
I would like to program in a cleaner way, by which I mean that I only want to put one single action on one single line, but I don't get it done (what's the signature of some_Method
, how to use it in order to define an action, ...?)
This is what I have until now:
public ... some_Method(...)
{
Confirmation conf = (Confirmation)c;
if (conf.Confirmed)
{
DoSomething();
}
}
Action actionToPerform = new Action(some_Method);
OwnObjectRequest.Raise(confirmation, actionToPerform);
有人知道怎么写这个吗?
我不认为用多行格式编写这样的一行程序有任何技术优势,但它将极大地帮助我理解如何阅读、理解并支持这一源代码.