Class Argument<T>
Base class for arguments
Implements
Inherited Members
Namespace: Benday.CommandsFramework
Assembly: Benday.CommandsFramework.dll
Syntax
public abstract class Argument<T> : IArgument
Type Parameters
| Name | Description |
|---|---|
| T | The data type for the argument |
Constructors
| Edit this page View SourceArgument(string)
Declaration
public Argument(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Properties
| Edit this page View SourceAlias
The alternate name of the argument when used on the command line
Declaration
public string Alias { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
AllowEmptyValue
Is an empty value valid? This is more helpful for boolean arguments when the existence of the argument on the command line call indicates that something should be done.
Declaration
public bool AllowEmptyValue { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
AllowedValues
List of valid values for this argument. Empty array means any value is accepted. When non-empty, the argument value must match one of these values (case-insensitive).
Declaration
public virtual string[] AllowedValues { get; set; }
Property Value
| Type | Description |
|---|---|
| string[] |
DataType
Data type for this argument
Declaration
public abstract ArgumentDataType DataType { get; }
Property Value
| Type | Description |
|---|---|
| ArgumentDataType |
DefaultValue
The explicit default value for this argument as configured by WithDefaultValue(). Never changed by values supplied on the command line or from configuration.
Declaration
public string DefaultValue { get; }
Property Value
| Type | Description |
|---|---|
| string |
Description
Human readable description of this argument
Declaration
public string Description { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
FriendlyName
Human readable friendly name for this argument
Declaration
public string FriendlyName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
HasAlias
Returns true if a command name alias is set
Declaration
public bool HasAlias { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasDefaultValue
Returns true when an explicit default value has been configured. This is false for the implicit type default that every argument starts with.
Declaration
public bool HasDefaultValue { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasValue
Does this argument have a value?
Declaration
public bool HasValue { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsFromConfig
Should this value come from configuration instead of command line? The value can still be overridden via command line.
Declaration
public bool IsFromConfig { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
IsPositionalSource
Should this value come from an unnamed argument on the command line? If yes, the Alias value will be the POSITION_x.
Declaration
public bool IsPositionalSource { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
IsRequired
Is this argument required to have a value in order to be valid?
Declaration
public bool IsRequired { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Name
The name of the argument when used on the command line
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Value
The value of this argument
Declaration
public T Value { get; set; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
| Edit this page View SourceGetDefaultValue()
Get the default value for this argument for this data type
Declaration
protected abstract T GetDefaultValue()
Returns
| Type | Description |
|---|---|
| T |
OnInitialize()
Template method for adding logic at the end of the initialization process
Declaration
protected virtual void OnInitialize()
TrySetDefaultValue(string)
Records an explicit default value for this argument and applies it as the current value. If the value cannot be converted to the argument's data type then nothing is recorded and the argument is left untouched.
Declaration
public bool TrySetDefaultValue(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| string | input | String representation of the default value |
Returns
| Type | Description |
|---|---|
| bool | True if the default value was valid and was recorded |
TrySetValue(string)
Try to set the value for this argument
Declaration
public abstract bool TrySetValue(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| string | input | String representation of the argument value |
Returns
| Type | Description |
|---|---|
| bool | True if the value could be converted to the argument's data type and the value was set |
Validate()
Validate this argument according to the configuration.
Declaration
public virtual bool Validate()
Returns
| Type | Description |
|---|---|
| bool | True if the argument is valid |