我试图在另一个动作中设置一个动作,但我传递给它的动作最终仍然为空。这是一个愚蠢的例子:
Action<Action<VerifylocalResult>> docollectprint = (vl) =>
{
vl = (vlocres) =>
{
//DoStuff
};
//This returns false, indicating the action has been set:
Console.WriteLine((vl == null).ToString());
};
//Hookups
docollectprint(vlocobj.Action_NotExists);
//This returns true, so the action has not been set:
Console.WriteLine((vlocobj.Action_NotExists==null).ToString());
我已经尝试过传递一个getter方法而不是真正的交易,但结果是一样的..它最终仍然是空的。
Action<Func<Action<VerifylocalResult>>> docollectprint = (vl) =>
{
Action<VerifylocalResult> theaction = vl();
theaction = (vlocres) =>
{
//DoStuff
};
//This returns false, indicating the action has been set
Console.WriteLine((theaction == null).ToString());
};
//Hookups
docollectprint(() => { return vlocobj.Action_NotExists; });
//This returns true, so the action has not been set
Console.WriteLine((vlocobj.Action_NotExists==null).ToString());
有没有办法做到这一点?另外,很抱歉,如果以前有人问过这个问题,但是当我搜索时,我发现的只是人们试图做的事情Action<ref string x>
或类似的事情。
更新(解决方案):
Func<string, Action<VerifylocalResult>> docollectprint = (msg) =>
{
Action<VerifylocalResult> vl = (vlocres) =>
{
/*DoStuff*/
};
return vl;
};
//Hookups
vlocobj.Action_NotExists = docollectprint("x");