Class Option
The Option class is a runtime validated representation of an actual command option and its value passed by a user or an application.
public sealed class Option : IEquatable<Option?>, IValue
- Inheritance
-
Option
- Implements
- Inherited Members
Remarks
An option id is always unique within a command. By design Option implements the default equality IEquatable<T> and GetHashCode() using Id property. Thus, two options with the same id are equal irrespective of other property values. This is done to improve performance during lookup and avoid multiple options with same identifiers.
The options can have same ids across multiple commands. Each Command has OptionDescriptors collection that contains options with unique ids.
Constructors
Option(OptionDescriptor, object)
Initialize a new instance..
[JsonConstructor]
public Option(OptionDescriptor optionDescriptor, object value)
Parameters
optionDescriptor
OptionDescriptorThe option descriptor.
value
objectThe option value.
Properties
Alias
The option alias.
[JsonIgnore]
public string? Alias { get; }
Property Value
DataType
The option data type.
[JsonIgnore]
public string DataType { get; }
Property Value
Description
The option description.
[JsonIgnore]
public string? Description { get; }
Property Value
Descriptor
The option descriptor.
[JsonPropertyName("descriptor")]
public OptionDescriptor Descriptor { get; }
Property Value
Id
The option id.
[JsonIgnore]
public string Id { get; }
Property Value
Remarks
The option id is unique with in a command.
Value
The option value.
[JsonPropertyName("value")]
public object Value { get; set; }
Property Value
Methods
ChangeValueType(Type)
Changes the option value to the specified type.
public void ChangeValueType(Type type)
Parameters
type
TypeThe new type to use.
Equals(Option?)
Indicates whether the current option is equal to another option.
public bool Equals(Option? other)
Parameters
other
OptionThe other option.
Returns
- bool
true
if the current option is equal to the other option; otherwise, false.
Equals(object?)
Indicates whether the current option is equal to another option.
public override bool Equals(object? obj)
Parameters
obj
objectThe other option.
Returns
- bool
true
if the current option is equal to the other option; otherwise, false.
GetHashCode()
Returns the hash code for this option.
public override int GetHashCode()
Returns
Operators
operator ==(Option?, Option?)
Indicates whether the current option is equal to another option.
public static bool operator ==(Option? left, Option? right)
Parameters
Returns
- bool
true
if the current option is equal to the other option; otherwise, false.
operator !=(Option?, Option?)
Indicates whether the current option is not equal to another option.
public static bool operator !=(Option? left, Option? right)
Parameters
Returns
- bool
true
if the current option is not equal to the other option; otherwise, false.