Show / Hide Table of Contents

Class Argument<T>

Base class for arguments

Inheritance
object
Argument<T>
BooleanArgument
DateTimeArgument
Int32Argument
StringArgument
Implements
IArgument
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
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 Source

Argument(string)

Declaration
public Argument(string name)
Parameters
Type Name Description
string name

Properties

| Edit this page View Source

Alias

The alternate name of the argument when used on the command line

Declaration
public string Alias { get; set; }
Property Value
Type Description
string
| Edit this page View Source

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
| Edit this page View Source

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[]
| Edit this page View Source

DataType

Data type for this argument

Declaration
public abstract ArgumentDataType DataType { get; }
Property Value
Type Description
ArgumentDataType
| Edit this page View Source

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
| Edit this page View Source

Description

Human readable description of this argument

Declaration
public string Description { get; set; }
Property Value
Type Description
string
| Edit this page View Source

FriendlyName

Human readable friendly name for this argument

Declaration
public string FriendlyName { get; set; }
Property Value
Type Description
string
| Edit this page View Source

HasAlias

Returns true if a command name alias is set

Declaration
public bool HasAlias { get; }
Property Value
Type Description
bool
| Edit this page View Source

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
| Edit this page View Source

HasValue

Does this argument have a value?

Declaration
public bool HasValue { get; }
Property Value
Type Description
bool
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

Name

The name of the argument when used on the command line

Declaration
public string Name { get; set; }
Property Value
Type Description
string
| Edit this page View Source

Value

The value of this argument

Declaration
public T Value { get; set; }
Property Value
Type Description
T

Methods

| Edit this page View Source

GetDefaultValue()

Get the default value for this argument for this data type

Declaration
protected abstract T GetDefaultValue()
Returns
Type Description
T
| Edit this page View Source

OnInitialize()

Template method for adding logic at the end of the initialization process

Declaration
protected virtual void OnInitialize()
| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

Validate()

Validate this argument according to the configuration.

Declaration
public virtual bool Validate()
Returns
Type Description
bool

True if the argument is valid

Implements

IArgument

Extension Methods

ExtensionMethods.AllowEmptyValue<T>(Argument<T>, bool)
ExtensionMethods.AsNotRequired<T>(Argument<T>)
ExtensionMethods.AsRequired<T>(Argument<T>)
ExtensionMethods.ExistenceOptional<T>(Argument<T>)
ExtensionMethods.FromConfig<T>(Argument<T>)
ExtensionMethods.FromPositionalArgument<T>(Argument<T>, int)
ExtensionMethods.MustExist<T>(Argument<T>)
ExtensionMethods.WithAlias<T>(Argument<T>, string)
ExtensionMethods.WithDefaultValue<T>(Argument<T>, T)
ExtensionMethods.WithDescription<T>(Argument<T>, string)
ExtensionMethods.WithFriendlyName<T>(Argument<T>, string)
  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com