@@ -8,14 +8,40 @@ namespace System.CommandLine.Subsystems.Annotations;
8
8
/// <summary>
9
9
/// Allows associating an annotation with a <see cref="CliSymbol"/>. The annotation will be stored by the accessor's owner <see cref="CliSubsystem"/>.
10
10
/// </summary>
11
+ /// <remarks>
12
+ /// The annotation will be stored by the accessor's owner <see cref="CliSubsystem"/>.
13
+ /// </summary>
14
+ /// <typeparam name="TValue">The type of value to be stored</typeparam>
15
+ /// <param name="owner">The subsystem that this annotation store data for.</param>
16
+ /// <param name="id">The identifier for this annotation, since subsystems may have multiple annotations.</param>
17
+ /// <param name="defaultValue">The default value to return if the annotation is not set.</param>
11
18
public struct AnnotationAccessor < TValue > ( CliSubsystem owner , AnnotationId < TValue > id , TValue ? defaultValue = default )
12
19
{
13
20
/// <summary>
14
- /// The ID of the annotation
21
+ /// The identifier for this annotation, since subsystems may have multiple annotations.
15
22
/// </summary>
16
23
public AnnotationId < TValue > Id { get ; } = id ;
24
+
25
+ /// <summary>
26
+ /// Store a value for the annotation and symbol
27
+ /// </summary>
28
+ /// <param name="symbol">The CliSymbol the value is for.</param>
29
+ /// <param name="value">The value to store.</param>
17
30
public readonly void Set ( CliSymbol symbol , TValue value ) => owner . SetAnnotation ( symbol , Id , value ) ;
31
+
32
+ /// <summary>
33
+ /// Retrieve the value for the annotation and symbol
34
+ /// </summary>
35
+ /// <param name="symbol">The CliSymbol the value is for.</param>
36
+ /// <param name="value">The value to retrieve/</param>
37
+ /// <returns>True if the value was found, false otherwise.</returns>
18
38
public readonly bool TryGet ( CliSymbol symbol , [ NotNullWhen ( true ) ] out TValue ? value ) => owner . TryGetAnnotation ( symbol , Id , out value ) ;
39
+
40
+ /// <summary>
41
+ /// Retrieve the value for the annotation and symbol
42
+ /// </summary>
43
+ /// <param name="symbol">The CliSymbol the value is for.</param>
44
+ /// <returns>The retrieved value or <see cref="defaultValue"/> if the value was not found.</returns>
19
45
public readonly TValue ? Get ( CliSymbol symbol )
20
46
{
21
47
if ( TryGet ( symbol , out var value ) )
0 commit comments