我想從一個通用委託轉換爲一個命名委託。對實例方法的委託不能具有null'this'。當轉換委託人
有了結果如下(無效C#)的精神是:
Action<CustomClass> act = ???;
CustomDelegate d = act;
我已經試過
CustomDelegate d = act.Invoke;
CustomDelegate d = new CustomDelegate(act);
CustomDelegate d = new CustomDelegate(x => act(x));
CustomDelegate d = new CustomDelegate(act.Invoke);
所有這一切都不能在運行時錯誤
給人一種ArgumentException
對實例方法的委託不能具有null'this'。
堆棧這不是我的代碼的頂部是:
在System.MulticastDelegate.ThrowNullThisInDelegateToInstance()
在System.MulticastDelegate.CtorClosed(對象目標,IntPtr的methodPtr)
如何將一個委託轉換爲我沒有得到異常?