You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-4Lines changed: 29 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ internal class Program
41
41
privatestaticintInt { get; set; }
42
42
43
43
[Argument('s', "string")]
44
-
privatestaticstringString { get; set; }
44
+
privatestaticstring[]String { get; set; }
45
45
46
46
[Operands]
47
47
privatestaticstring[] Operands { get; set; }
@@ -50,11 +50,15 @@ internal class Program
50
50
{
51
51
Arguments.Populate();
52
52
53
-
Console.WriteLine("String: "+String);
54
53
Console.WriteLine("Bool: "+Bool);
55
54
Console.WriteLine("Int: "+Int);
56
55
Console.WriteLine("Double: "+Double);
57
56
57
+
foreach (stringsinString)
58
+
{
59
+
Console.WriteLine("String: "+s);
60
+
}
61
+
58
62
foreach (stringoperandinOperands)
59
63
{
60
64
Console.WriteLine("\r\n Operand:"+operand);
@@ -159,6 +163,20 @@ c | foo
159
163
hello | world
160
164
new | slashes are ok too
161
165
166
+
### Multiple Values
167
+
168
+
Arguments can accept multiple values, and when parsed a ```List<object>``` is returned if more than one value is specified. When using
169
+
the ```Populate()``` method, the underlying property for an argument accepting multiple values must be an array or List, otherwise
170
+
an ```InvalidCastException``` is thrown.
171
+
172
+
#### Example
173
+
174
+
```--list 1 --list 2 --list 3```
175
+
176
+
Key | Value
177
+
--- | ---
178
+
list | 1,2,3
179
+
162
180
### Operands
163
181
164
182
Any text in the string that doesn't match the argument-value format is considered an operand. Any text which appears after a double-hyphen ```--```, not enclosed in single or double quotes, and with spaces on either side,
@@ -222,7 +240,10 @@ Use the ```Argument``` attribute to designate properties to be populated. The c
222
240
Note that the name of the property doesn't matter; only the attribute values are used to match an argument key to a property.
223
241
224
242
The Type of the property does matter; the code attempts to convert argument values from string to the specified Type, and if the conversion fails
225
-
an ```ArgumentException``` is thrown.
243
+
an ```ArgumentException``` is thrown.
244
+
245
+
Properties can accept lists of parameters, as long as they are backed by an array or ```List<>```. Specifying multiple parameters for an argument backed
246
+
by an atomic Type (e.g. not an array or List) will result in an ```InvalidCastException```.
226
247
227
248
The ```Operands``` property accepts no parameters. If the property type is not ```string[]``` or ```List<string>```, an
0 commit comments