diff --git a/src/System.CommandLine.StaticCompletions/DynamicSymbolExtensions.cs b/src/System.CommandLine.StaticCompletions/DynamicSymbolExtensions.cs index c59d18c7bec1..18c7275540da 100644 --- a/src/System.CommandLine.StaticCompletions/DynamicSymbolExtensions.cs +++ b/src/System.CommandLine.StaticCompletions/DynamicSymbolExtensions.cs @@ -6,6 +6,8 @@ namespace System.CommandLine.StaticCompletions; /// public static class DynamicSymbolExtensions { + private static readonly Lock s_guard = new(); + /// /// The state that is used to track which symbols are dynamic. /// @@ -18,38 +20,44 @@ public static class DynamicSymbolExtensions /// public bool IsDynamic { - get => s_dynamicSymbols.GetValueOrDefault(option, false); - set => s_dynamicSymbols[option] = value; - } - - /// - /// Mark this option as requiring dynamic completions. - /// - /// - public Option RequiresDynamicCompletion() - { - option.IsDynamic = true; - return option; + get + { + lock (s_guard) + { + return s_dynamicSymbols.GetValueOrDefault(option, false); + } + } + set + { + lock (s_guard) + { + s_dynamicSymbols[option] = value; + } + } } } extension(Argument argument) { - /// Indicates whether this argument requires a dynamic call into the dotnet process to compute completions. - public bool IsDynamic - { - get => s_dynamicSymbols.GetValueOrDefault(argument, false); - set => s_dynamicSymbols[argument] = value; - } - /// - /// Mark this argument as requiring dynamic completions. + /// Indicates whether this argument requires a dynamic call into the dotnet process to compute completions. /// - /// - public Argument RequiresDynamicCompletion() + public bool IsDynamic { - argument.IsDynamic = true; - return argument; + get + { + lock (s_guard) + { + return s_dynamicSymbols.GetValueOrDefault(argument, false); + } + } + set + { + lock (s_guard) + { + s_dynamicSymbols[argument] = value; + } + } } } }