Skip to content

Commit b4485d8

Browse files
authored
Merge pull request #2530 from MiYanni/OptionValueType
Add ValueType to Option
2 parents b7f0d1c + ab013c2 commit b4485d8

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
System.CommandLine
1+
System.CommandLine
22
public abstract class Argument : Symbol
33
public ArgumentArity Arity { get; set; }
44
public System.Collections.Generic.List<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> CompletionSources { get; }
@@ -98,11 +98,13 @@ System.CommandLine
9898
public System.Boolean Recursive { get; set; }
9999
public System.Boolean Required { get; set; }
100100
public System.Collections.Generic.List<System.Action<System.CommandLine.Parsing.OptionResult>> Validators { get; }
101+
public System.Type ValueType { get; }
101102
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
102103
public class Option<T> : Option
103104
.ctor(System.String name, System.String[] aliases)
104105
public Func<System.CommandLine.Parsing.ArgumentResult,T> CustomParser { get; set; }
105106
public Func<System.CommandLine.Parsing.ArgumentResult,T> DefaultValueFactory { get; set; }
107+
public System.Type ValueType { get; }
106108
public System.Void AcceptLegalFileNamesOnly()
107109
public System.Void AcceptLegalFilePathsOnly()
108110
public System.Void AcceptOnlyFromAmong(System.String[] values)

src/System.CommandLine/Option.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public ArgumentArity Arity
6262
/// </summary>
6363
public bool Recursive { get; set; }
6464

65+
/// <summary>
66+
/// Gets the <see cref="Type" /> that the option's parsed tokens will be converted to.
67+
/// </summary>
68+
public abstract Type ValueType { get; }
69+
6570
/// <summary>
6671
/// Validators that will be called when the option is matched by the parser.
6772
/// </summary>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public Func<ArgumentResult, T>? DefaultValueFactory
4444

4545
internal sealed override Argument Argument => _argument;
4646

47+
/// <inheritdoc />
48+
public override Type ValueType => _argument.ValueType;
49+
4750
/// <summary>
4851
/// Configures the option to accept only the specified values, and to suggest them as command line completions.
4952
/// </summary>

0 commit comments

Comments
 (0)