Skip to content

Commit 99dcf27

Browse files
authored
Merge pull request #746 from jonsequitur/more-Option-of-T-constructors
more Option<T> constructors!
2 parents 7194c8c + de38bb0 commit 99dcf27

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/System.CommandLine/Option{T}.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public Option(string alias) : base(alias)
1212
Argument = new Argument<T>();
1313
}
1414

15+
public Option(string[] aliases) : base(aliases)
16+
{
17+
Argument = new Argument<T>();
18+
}
19+
1520
public Option(string alias, string description) : base(alias, description)
1621
{
1722
Argument = new Argument<T>();
@@ -75,6 +80,31 @@ public Option(
7580

7681
Argument = new Argument<T>(getDefaultValue);
7782
}
83+
public Option(
84+
string alias,
85+
T defaultValue,
86+
string description = null) : base(alias, description)
87+
{
88+
if (defaultValue is null)
89+
{
90+
throw new ArgumentNullException(nameof(defaultValue));
91+
}
92+
93+
Argument = new Argument<T>(() => defaultValue);
94+
}
95+
96+
public Option(
97+
string[] aliases,
98+
T defaultValue,
99+
string description = null) : base(aliases, description)
100+
{
101+
if (defaultValue is null)
102+
{
103+
throw new ArgumentNullException(nameof(defaultValue));
104+
}
105+
106+
Argument = new Argument<T>(() => defaultValue);
107+
}
78108

79109
public override Argument Argument
80110
{

0 commit comments

Comments
 (0)