I'm writing an API method, with two arguments, both of which want to accept "one or more paths". A path in my case is an NPath reference, and I want to be able to call my method both like this:
var mypath1 = new NPath("mydir/myfile.txt");
var mypath2 = new Npath("file2");
myMethod(mypath, mypath2);
as well as with an IEnumerable
IEnumerable<NPath> paths1 = fromsomewhere();
IEnumerable<NPath> paths2 = fromsomewhereelse();
myMethod(paths1, paths2);
How would you write such a method?
I'd like to do this without overloads, since my method will more than 2 arguments eventually that should allow taking one or many, and the overload explosion just grows out of control. I tried writing a OneOrMorePaths struct that has an implicit operator from a NPath as well as from IEnumerable, but you're not allowed to write implicit operators that take interfaces as inputs.
One more constraint, I do not want NPath's to always be convertible to IEnumerable. only when the method explicitelly says it's ok to pass one or more.