[Mono-dev] Program Option Parsing Library
Jay Logue
jay-MonoDev at toaster.com
Fri Jan 11 13:25:51 EST 2008
Jonathan Pryor wrote:
> Indeed. I like return values. :-)
>
Hey, I gave it a shot. :-)
> Now how should localization be handled? Should it?
It only seems fair. I would do the localization in the OptionException
class itself. I see other mono Exception types calling Locale.GetText()
to translate their text (e.g. FileNotFoundException), but I don't see
where its declared. (I see one in
mcs/class/Managed.Windows.Forms/Assembly/Locale.cs but I don't think
that's it).
A couple of other thoughts:
-- I think it would be convenient to the user if the error message
included the option value whenever ConvertFromString() failed. That way
if there are many instances of the same option the user can easily
figure out which one is causing the problem. An alternative is to
include the index of the offending argument as a property of the
OptionException, leaving it to the caller's exception handler to point
out the value.
-- I was looking at your FooConverter example and it occurred to me that
the code might be more concise if Options.Add<T>() had an overload that
took a TypeConverter. That way I could simply say:
Options p = new Options () {
{ "v", v => ++verbose },
{ "foo", *new FooConverter()*, (int v) => foo = v },
{ "h|?|help", v => ShowHelp () }
};
... rather than having to use a wrapper type (Foo) as a stand-in for the
real type.
Please feel free to tell me to shut up when you've had enough of my
'thoughts'. :-)
-- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080111/60a560ad/attachment.html
More information about the Mono-devel-list
mailing list