Class ArgumentCollection
Collection of arguments. Two common use cases: 1) create a collection of arguments in order to describe what arguments are available for a command and 2) to represent the arguments on a command with the values populated from the command line.
Inherited Members
Namespace: Benday.CommandsFramework
Assembly: Benday.CommandsFramework.dll
Syntax
public class ArgumentCollection : IEnumerable<IArgument>, IEnumerable
Constructors
| Edit this page View SourceArgumentCollection()
Constructor. Creates an empty argument collection.
Declaration
public ArgumentCollection()
ArgumentCollection(Dictionary<string, IArgument>)
Constructor. Creates the argument collection and populates it with arguments in the supplied dictionary.
Declaration
public ArgumentCollection(Dictionary<string, IArgument> fromDictionary)
Parameters
| Type | Name | Description |
|---|---|---|
| Dictionary<string, IArgument> | fromDictionary | Dictionary of keys and values that will be used to populate this argument collection |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException |
ArgumentCollection(Dictionary<string, string>)
Constructor. Creates the argument collection and populates it with string arguments and values from the supplied dictionary.
Declaration
public ArgumentCollection(Dictionary<string, string> fromDictionary)
Parameters
| Type | Name | Description |
|---|---|---|
| Dictionary<string, string> | fromDictionary | Dictionary of keys and values that will be used to populate this argument collection |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| InvalidOperationException |
Fields
| Edit this page View SourceArgumentNameComparer
Comparer used to match argument names and aliases supplied on the command line against the argument definitions for a command. Argument names are matched without regard to case, so '/Verbose', '/verbose' and '/VERBOSE' all reach the same argument.
Declaration
public static readonly StringComparer ArgumentNameComparer
Field Value
| Type | Description |
|---|---|
| StringComparer |
Properties
| Edit this page View SourceCount
Number of arguments in this collection
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
this[string]
Indexer. Get the argument by argument name
Declaration
public IArgument this[string key] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Name of the argument |
Property Value
| Type | Description |
|---|---|
| IArgument | Returns the argument if it exists |
Keys
Collection of argument keys/names managed
Declaration
public Dictionary<string, IArgument>.KeyCollection Keys { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, IArgument>.KeyCollection |
UnrecognizedKeys
Argument keys supplied on the command line that were not recognized by this command's argument definitions. Populated during SetValues(). Use this to detect typos or unsupported arguments.
Declaration
public List<string> UnrecognizedKeys { get; }
Property Value
| Type | Description |
|---|---|
| List<string> |
Methods
| Edit this page View SourceAdd(string, IArgument)
Add an argument to the collection
Declaration
public void Add(string key, IArgument value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Name of the argument |
| IArgument | value | The populated argument to add |
Add(string, string)
Add a string argument and value
Declaration
public void Add(string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Name of the argument |
| string | value | Value for the argument |
ContainsKey(string)
Does this collection have an argument with this name/key?
Declaration
public bool ContainsKey(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Name of the argument |
Returns
| Type | Description |
|---|---|
| bool | True if it exists in this collection |
GetEnumerator()
Enumerator
Declaration
public IEnumerator<IArgument> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<IArgument> | Enumerator for the arguments in this collection |
Remove(string)
Remove an argument
Declaration
public void Remove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Name of the argument to remove |
SetValues(Dictionary<string, string>)
For an argument collection that already has arguments defined, populate those argument definitions with values. This is typically the arguments from the command line.
Declaration
public void SetValues(Dictionary<string, string> fromArguments)
Parameters
| Type | Name | Description |
|---|---|---|
| Dictionary<string, string> | fromArguments | Key value pairs to set in to this collection |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |