Can I have a variable number of generic parameters?

You can’t. That is a key part of the API. You could, however, do something around the side, such as accepting a Type[] argument. You might also think up some exotic “fluent API / extension method” way of doing it, but to be honest it probably won’t be worth it; but something like:

obj.Merge<FirstType>(firstData).Merge<SecondType>(secondData)
     .Merge<ThirdType>(thirdData).Execute<TDestination>(dest);

or with generic type inference:

obj.Merge(firstData).Merge(secondData).Merge(thirdData).Execute(dest);

Each merge step would simple store away the work to do, only accessed by Execute.

Leave a Comment