Search code examples
c#-3.0rhino-mocks

RhinoMocks - Pass Action<T> as parameter


In RhinoMocks, there's Stub extension method, that takes Action<T>. For some reason this:

CurrentInvoice.Stub(i => i.TaxYear).Return(1);

works great, but this:

CurrentInvoice.Stub(new Action<Invoice>(i => i.TaxYear)).Return(1);

produces the compiler error: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

The intellisense for this method explicitly says that it expects Action<Invoice>, so I can't understand why the first works, but not the second.

The main relevance of this is that I'd like to be able to pass some of these configuration lambdas as parameters to a method, and I run into this same issue.

Thanks


Solution

  • Are you sure you're not accidentally using an overload for Stub which takes a Func<T, TResult> in the first line? I can't see why the first call would work otherwise.

    Do you have a link to API documentation?