views:

21

answers:

1

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

+3  A: 

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?

Jon Skeet
Thank you - I'll accept your answer in 8 minutes, for some reason.
Adam