Skip to content

Commit 1c290f6

Browse files
committed
Use the annotation resolver in ValueProvider
1 parent b5e7d05 commit 1c290f6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/System.CommandLine.Subsystems/ValueAnnotationExtensions.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ public static class ValueAnnotationExtensions
1717
/// <param name="option">The option</param>
1818
/// <returns>The option's default value annotation if any, otherwise <see langword="null"/></returns>
1919
/// <remarks>
20-
/// This is intended to be called by CLI authors. Subsystems should instead call <see cref="PipelineResult.GetValue{T}(CliOption)"/>,
21-
/// which calculates the actual default value, based on the default value annotation and default value calculation,
22-
/// whether directly stored on the symbol or from the subsystem's <see cref="IAnnotationProvider"/>.
20+
/// This is intended to be called by CLI authors inspecting the default value source they have
21+
/// associated directly with the <paramref name="valueSymbol"/>.
22+
/// <para>
23+
/// Subsystems should instead use <see cref="PipelineResult.GetValue(CliValueSymbol)"/>, which caches calculated
24+
/// values and respects dynamic/lazy annotations from the <see cref="Pipeline.AnnotationProviders"/>.
25+
/// </para>
2326
/// </remarks>
2427
public static bool TryGetDefaultValueSource(this CliValueSymbol valueSymbol, [NotNullWhen(true)] out ValueSource? defaultValueSource)
2528
=> valueSymbol.TryGetAnnotation(ValueAnnotations.DefaultValueSource, out defaultValueSource);

src/System.CommandLine.Subsystems/ValueProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.CommandLine.Subsystems.Annotations;
45
using System.CommandLine.ValueSources;
56

67
namespace System.CommandLine;
@@ -48,7 +49,7 @@ private bool TryGetValue<T>(CliSymbol symbol, out T? value)
4849
{
4950
return UseValue(valueSymbol, valueResult.GetValue<T>());
5051
}
51-
if (valueSymbol.TryGetDefaultValueSource(out ValueSource? defaultValueSource))
52+
if (pipelineResult.Annotations.TryGet(valueSymbol, ValueAnnotations.DefaultValueSource, out ValueSource? defaultValueSource))
5253
{
5354
if (defaultValueSource is not ValueSource<T> typedDefaultValueSource)
5455
{

0 commit comments

Comments
 (0)