-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from joncloud/enum-help
Implements better support for enum options
- Loading branch information
Showing
5 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
using System.Linq; | ||
|
||
namespace ThorNet | ||
{ | ||
internal class Option | ||
{ | ||
readonly string[] _possibleValues; | ||
|
||
public Option(OptionAttribute attribute) | ||
: this(attribute.Alias, attribute.Name) | ||
: this(attribute.Alias, attribute.Name, attribute.GetPossibleValues()) | ||
{ | ||
AllowFlag = attribute.Flag; | ||
} | ||
|
||
public Option(string alias, string name = null) | ||
public Option(string alias, string name = null, string[] possibleValues = null) | ||
{ | ||
Alias = alias; | ||
Name = name ?? alias; | ||
_possibleValues = possibleValues; | ||
} | ||
|
||
public string Alias { get; } | ||
public bool AllowFlag { get; set; } | ||
public string Name { get; } | ||
public string Value { get; set; } | ||
|
||
internal bool ShouldUseValue(string value) | ||
{ | ||
if (_possibleValues is null) return true; | ||
|
||
return _possibleValues.Contains(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters