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
The code is also designed to be incorporated into your project as a single source file (Arguments.cs).
22
+
21
23
## Quick Start
22
24
23
25
Create private static properties in the class containing your ```Main()``` and mark them with the ```Argument``` attribute, assigning short and long names. Invoke
@@ -41,6 +43,9 @@ internal class Program
41
43
[Argument('s', "string")]
42
44
privatestaticstringString { get; set; }
43
45
46
+
[Operands]
47
+
privatestaticstring[] Operands { get; set; }
48
+
44
49
privatestaticvoidMain(string[] args)
45
50
{
46
51
Arguments.Populate();
@@ -49,6 +54,11 @@ internal class Program
49
54
Console.WriteLine("Bool: "+Bool);
50
55
Console.WriteLine("Int: "+Int);
51
56
Console.WriteLine("Double: "+Double);
57
+
58
+
foreach (stringoperandinOperands)
59
+
{
60
+
Console.WriteLine("\r\n Operand:"+operand);
61
+
}
52
62
}
53
63
}
54
64
```
@@ -61,7 +71,7 @@ located [here](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap1
61
71
62
72
Each argument is treated as a key-value pair, regardless of whether a value is present. The general format is as follows:
The key-value pair may begin with a single dash, a pair of dashes (double dash), or a forward slash. Single and double dashes indicate the use of short
67
77
or long names, respectively, which are covered below. The forward slash may represent either, but does not allow for the grouping of parameterless
@@ -73,6 +83,9 @@ The value delimiter may be an equals sign, a colon, or a space.
73
83
74
84
Values may be any alphanumeric sequence, however if a value contains a space it must be enclosed in either single or double quotes.
75
85
86
+
Any word, or phrase enclosed in single or double quotes, will be parsed as an operand. The official specification requires operands to appear last, however this library will
87
+
parse them in any position.
88
+
76
89
### Short Names
77
90
78
91
Short names consist of a single character, and arguments without parameters may be grouped. A grouping may be terminated with a single argument containing
@@ -143,6 +156,23 @@ c | foo
143
156
hello | world
144
157
new | slashes are ok too
145
158
159
+
### Operands
160
+
161
+
Any text in the string that doesn't match the argument-value format is considered an operand.
162
+
163
+
#### Example
164
+
165
+
```-a foo bar "hello world" -b```
166
+
167
+
Key | Value
168
+
--- | ---
169
+
a | foo
170
+
b |
171
+
172
+
Operands
173
+
1. bar
174
+
2. "hello world"
175
+
146
176
## Parsing
147
177
148
178
Argument key-value pairs can be parsed from any string using the ```Parse(string)``` method. This method returns a
@@ -175,6 +205,9 @@ whether the argument was encountered in the command line arguments. All other v
175
205
The ```Populate()``` method uses reflection to populate private static properties in the target Type with the argument
176
206
values matching properties marked with the ```Argument``` attribute.
177
207
208
+
The list of operands is placed into a single property marked with the ```Operands``` attribute. This property must be
209
+
of type ```string[]``` or ```List<string>```.
210
+
178
211
### Creating Target Properties
179
212
180
213
Use the ```Argument``` attribute to designate properties to be populated. The constructor of ```Argument``` accepts a ```char``` and a
@@ -185,6 +218,9 @@ Note that the name of the property doesn't matter; only the attribute values are
185
218
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
186
219
an ```ArgumentException``` is thrown.
187
220
221
+
The ```Operands``` property accepts no parameters. If the property type is not ```string[]``` or ```List<string>```, an
0 commit comments