Convert this delegate to an anonymous method or lambda

后端 未结 4 926
忘掉有多难
忘掉有多难 2020-12-28 16:01

I am new to all the anonymous features and need some help. I have gotten the following to work:

public void FakeSaveWithMessage(Transaction t)
{
    t.Messa         


        
4条回答
  •  时光说笑
    2020-12-28 16:57

    The problem is not with your delegate definition, it's that the parameter of the Do() method is of type System.Delegate, and the compiler generated delegate type (FakeSave) does not implicitly convert to System.Delegate.

    Try adding a cast in front of your anonymous delegate:

    Expect.Call(delegate { _dao.Save(t); }).Do((Delegate)delegate { t.Message = "I drink goats blood"; });
    

提交回复
热议问题