@@ -13,41 +13,52 @@ namespace System.CommandLine;
13
13
public static class ValueConditionAnnotationExtensions
14
14
{
15
15
/// <summary>
16
- /// Set the upper and/or lower bound values of the range .
16
+ /// Set upper and/or lower bounds on the range of values that the symbol value may have .
17
17
/// </summary>
18
- /// <typeparam name="T">The type of the bounds.</typeparam>
18
+ /// <typeparam name="TValueSymbol">The type of the symbol whose value is bounded by the range.</typeparam>
19
+ /// <typeparam name="TValue">The type of the value that is bounded by the range.</typeparam>
19
20
/// <param name="symbol">The option or argument the range applies to.</param>
20
21
/// <param name="lowerBound">The lower bound of the range.</param>
21
22
/// <param name="upperBound">The upper bound of the range.</param>
22
23
// TODO: Add RangeBounds
23
24
// TODO: You should not have to set both...why not nullable?
24
- public static void SetRange < T > ( this CliValueSymbol symbol , T lowerBound , T upperBound )
25
- where T : IComparable < T >
25
+ public static void SetRange < TValueSymbol , TValue > ( this TValueSymbol symbol , TValue lowerBound , TValue upperBound )
26
+ where TValueSymbol : CliValueSymbol , ICliValueSymbol < TValue >
27
+ where TValue : IComparable < TValue >
26
28
{
27
- var range = new Range < T > ( lowerBound , upperBound ) ;
29
+ var range = new Range < TValue > ( lowerBound , upperBound ) ;
28
30
29
31
symbol . SetValueCondition ( range ) ;
30
32
}
31
33
32
34
/// <summary>
33
- /// Set the upper and/or lower bound via ValueSource. Implicit conversions means this
34
- /// generally just works with any <see cref="ValueSource">.
35
+ /// Set upper and/or lower <see cref=" ValueSource"> bounds on the range of values that the symbol value may have.
36
+ /// Implicit conversions means this generally just works with any <see cref="ValueSource">.
35
37
/// </summary>
36
- /// <typeparam name="T">The type of the bounds.</typeparam>
38
+ /// <typeparam name="TValueSymbol">The type of the symbol whose value is bounded by the range.</typeparam>
39
+ /// <typeparam name="TValue">The type of the value that is bounded by the range.</typeparam>
37
40
/// <param name="symbol">The option or argument the range applies to.</param>
38
41
/// <param name="lowerBound">The <see cref="ValueSource"> that is the lower bound of the range.</param>
39
42
/// <param name="upperBound">The <see cref="ValueSource"> that is the upper bound of the range.</param>
40
43
// TODO: Add RangeBounds
41
44
// TODO: You should not have to set both...why not nullable?
42
- public static void SetRange < T > ( this CliValueSymbol symbol , ValueSource < T > lowerBound , ValueSource < T > upperBound )
43
- where T : IComparable < T >
45
+ public static void SetRange < TValueSymbol , TValue > ( this TValueSymbol symbol , ValueSource < TValue > lowerBound , ValueSource < TValue > upperBound )
46
+ where TValueSymbol : CliValueSymbol , ICliValueSymbol < TValue >
47
+ where TValue : IComparable < TValue >
44
48
// TODO: You should not have to set both...why not nullable?
45
49
{
46
- var range = new Range < T > ( lowerBound , upperBound ) ;
50
+ var range = new Range < TValue > ( lowerBound , upperBound ) ;
47
51
48
52
symbol . SetValueCondition ( range ) ;
49
53
}
50
54
55
+ /// <summary>
56
+ /// Get the upper and/or lower bound of the symbol's value.
57
+ /// </summary>
58
+ /// <param name="symbol">The option or argument the range applies to.</param>
59
+ public static ValueConditions . Range ? GetRange ( this CliValueSymbol symbol )
60
+ => symbol . GetValueCondition < ValueConditions . Range > ( ) ;
61
+
51
62
/// <summary>
52
63
/// Indicates that there is an inclusive group of options and arguments for the command. All
53
64
/// members of an inclusive must be present, or none can be present.
0 commit comments