Skip to content

Multi Culture Support

moh-hassan edited this page Jul 7, 2020 · 2 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.

Suppose you define an Option class like:

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(with => with.ParsingCulture = new CultureInfo("it-IT"));

Remarks: CommandLine.Parser.Default is a singleton uses CultureInfo.InvariantCulture.

Setting CultureInfo in Console application

CultureInfo ci = new CultureInfo("it-IT");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;

See also

Clone this wiki locally