Search code examples
c#-4.0named-parametersmassive

How did they implement this syntax in the Massive Micro-ORM, multiple args parameters?


Here on this page, Scott Hanselman shows two examples from Micro-ORMs Dapper and Massive, and the Massive-example caught my interested, because I don't see how they could implement that syntax.

The example is as follows, where I'm going to break it over several lines instead of just one long one:

var tbl = new Products();
var products = tbl.All(where: "CategoryID = @0 AND UnitPrice > @1",
    orderBy: "ProductName", limit: 20, args: 5,20);
                                       ^----+---^
                                            |
                                            +-- this

How did they implement this syntax, allowing args to have multiple values? I'm assuming params-based arguments, because that's the only thing that allows for that, but I don't understand how they constructed the method to allow for that since it seems to me that all I try ends up complaining about named arguments and fixed position arguments are in the wrong order.

I tried a test-method like this:

public static void Test(string name, int age, params object[] args)
{
}

and then using named arguments:

Test(age: 40, name: "Lasse", args: 10, 25);

But all I get is this:

Named argument specifications must appear after all fixed arguments have been specified

so obviously that is wrong. Also I can't see in the source anything that would allow for this but maybe I'm looking in the wrong place.

What am I missing here?


Solution

  • Actually I think that Mr. Hanselman showed some code that doesn't compile (oops, did I really dare to say that?). I can only get it working like this:

     Test(age: 40, name: "Lasse", args: new object[] { 10, 25 });