This is an update of the technique mentioned in an antique post by Robert Pickering which was referenced by Laurent Le Brun last summer. I've taken Laurent's example of F# usage and ported it to C# in the most direct fashion:
It is possible to streamline this to hide most of the messy type names inside utilities.
One thing I've not managed to do is get the lambda associated with the
ArgType.Rest to fire, even after setting the default handler
FSharpOption<T>.None. That -- the default handler -- gets fired every time an otherwise unmatched argument is encountered; the
ArgType.Rest handler looks from the code like it should "just work" so I'm a bit baffled ATM.
LATER: Mystery solved
Of course, I was testing this at a PowerShell prompt -- and the shell was swallowing the unquoted "--" string : there was no "rest" to operate on.