Skip to content

Commit fc074ef

Browse files
committed
Store AnnotationsId prefix as separate field
Avoiding the concat will marginally reduce the amount of heap memory, but more importantly makes it cleaner for annotation providers to check the prefix of the requested annotation ID.
1 parent 6026408 commit fc074ef

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/System.CommandLine.Subsystems/Subsystems/AnnotationId.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ namespace System.CommandLine.Subsystems;
66
/// <summary>
77
/// Describes the ID and type of an annotation.
88
/// </summary>
9-
public record struct AnnotationId<TValue>(string Id);
9+
public record struct AnnotationId<TValue>(string Prefix, string Id)
10+
{
11+
public override readonly string ToString() => $"{Prefix}.{Id}";
12+
}

src/System.CommandLine.Subsystems/Subsystems/Annotations/HelpAnnotations.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.CommandLine.Subsystems.Annotations;
88
/// </summary>
99
public static class HelpAnnotations
1010
{
11-
// I made this public because we need an identifier for subsystem Kind, and I think this makes a very good one.
12-
public static string Prefix { get; } = "Help.";
13-
public static AnnotationId<string> Description { get; } = new(Prefix + nameof(Description));
11+
public static string Prefix { get; } = nameof(SubsystemKind.Help);
12+
13+
public static AnnotationId<string> Description { get; } = new(Prefix, nameof(Description));
1414
}

src/System.CommandLine.Subsystems/Subsystems/Annotations/VersionAnnotations.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.CommandLine.Subsystems.Annotations;
88
/// </summary>
99
public static class VersionAnnotations
1010
{
11-
// I made this public because we need an identifier for subsystem Kind, and I think this makes a very good one.
12-
public static string Prefix { get; } = "Version."; // TODO: Decide between const and property. Isn't a const baked in at the callsite? Would that be OK when this is public?
13-
public static AnnotationId<string> Version { get; } = new(Prefix + nameof(Version));
11+
public static string Prefix { get; } = nameof(SubsystemKind.Version);
12+
13+
public static AnnotationId<string> Version { get; } = new(Prefix, nameof(Version));
1414
}

0 commit comments

Comments
 (0)