-
Notifications
You must be signed in to change notification settings - Fork 293
Advanced Topics
gsscoder edited this page Feb 21, 2013
·
12 revisions
The parser is culture-aware. The args[] array passed to ParseArguments is a string array, so when the parser loads data into target instance every string undergoes a conversion.
Now suppose you define a target class like this:
class Options {
[Option('v', "value")]
public double SomeValue { get; set; }
}
If your system use a dot as decimal separator and you type the following command line:
$ app -v 10,4
the parsing process will fail.
If you want that parsing occurs with a particular culture, just set desired CultureInfo in settings instance.
var parser = new CommandLine.Parser(new ParserSetting{ ParsingCulture = new CultureInfo("it-IT") });
// or
var parser = new CommandLine.Parser(with => with.UseCulture(new CultureInfo("it-IT"));
Please note that default behavior can change in future versions, so I suggest you to always explicit your culture preference.
Remarks: from Version 1.9.4.225 CommandLine.Parser.Default
default singleton uses already CultureInfo.InvariantCulture.