Is there going to be some sugar with Moq and C# Named/Optional parameters?
This idea just came out of nowhere, but I'm curious to hear what everyone thinks...
First off, is named/optional parameters supported with interfaces in C# 4.0? Or is that thought of as an implementation detail and interface contracts shouldn't specify "defaults".
Assuming they can. (I don't have time to install Dev10 and spike it)
Given this interface
public interface IService
{
void Calculate(byte p1, decimal p2 = 2.3m, decimal p3 = .05m, int p4 = 123);
}
Where currently (in C# 3.5 land) we do this this...
MockService.Setup(s => s.Calculate( It.IsAny<byte>(),
It.IsAny<decimal>(), // optional
It.IsAny<decimal>(), // optional
It.IsAny<int>()); // optional
could look like this in C# 4.0...
MockService.Setup(s => s.Calculate( It.IsAny<byte>(),
/*I have no idea how this syntax would look, but let's pretend you get my point */
p3: It.IsAny<decimal>() ); // as opposed to the "default = .05m" specified in the interface
So the mock recording would pickup any calls to this Calculate where the p1 is any byte, the p3 is any decimal and p2 & p4 are their "default" values.
Thoughts? (am I making any sense?)