別のアクション内にアクションを設定しようとしていますが、それに渡すアクションは最終的にはまだ null です。以下は簡単な例です:
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());
実際の取引の代わりにゲッターメソッドを渡そうとしましたが、結果は同じです..最終的にはまだnullです。
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");