'C#: CommandLineParser, how to pass an array of strings?
I'm using CommandLineParser and I want to pass multiple arguments which should end up in a single array. Here's my class:
public class ClientConfig : Config
{
[Option("load")]
public string[]? Load { get; set; }
}
When I use the following command line:
my.exe --load=1 --load=2 --load=3
When parsed my "Load" property should be the following: ["1", "2", "3"]. However when I try this I get the following exception:
System.InvalidOperationException: 'Sequence contains no elements'
How can I fix this?
Solution 1:[1]
In the docs it uses IEnumerable for array of string so by this ClientConfig:
public class ClientConfig
{
[Option("load")]
public IEnumerable<string> Load { get; set; }
}
this worked for me:
my.exe --load 1 2 3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
