// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable enable using System; using System.Collections.Immutable; #if CODE_STYLE namespace Microsoft.CodeAnalysis.Internal.Options #else namespace Microsoft.CodeAnalysis.Options #endif { /// /// Marker interface for /// internal interface ILanguageSpecificOption : IOptionWithGroup { } /// /// An global option. An instance of this class can be used to access an option value from an OptionSet. /// public class Option : ILanguageSpecificOption { /// /// Feature this option is associated with. /// public string Feature { get; } /// /// Optional group/sub-feature for this option. /// internal OptionGroup Group { get; } /// /// The name of the option. /// public string Name { get; } /// /// The default value of the option. /// public T DefaultValue { get; } /// /// The type of the option value. /// public Type Type => typeof(T); public ImmutableArray StorageLocations { get; } [Obsolete("Use a constructor that specifies an explicit default value.")] public Option(string feature, string name) : this(feature, name, default!) { // This constructor forwards to the next one; it exists to maintain source-level compatibility with older callers. } public Option(string feature, string name, T defaultValue) : this(feature, name, defaultValue, storageLocations: Array.Empty()) { } public Option(string feature, string name, T defaultValue, params OptionStorageLocation[] storageLocations) : this(feature, group: OptionGroup.Default, name, defaultValue, storageLocations) { } internal Option(string feature, OptionGroup group, string name, T defaultValue, params OptionStorageLocation[] storageLocations) { if (string.IsNullOrWhiteSpace(feature)) { throw new ArgumentNullException(nameof(feature)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException(nameof(name)); } this.Feature = feature; this.Group = group ?? throw new ArgumentNullException(nameof(group)); this.Name = name; this.DefaultValue = defaultValue; this.StorageLocations = storageLocations.ToImmutableArray(); } object? IOption.DefaultValue => this.DefaultValue; bool IOption.IsPerLanguage => false; OptionGroup IOptionWithGroup.Group => this.Group; public override string ToString() { return string.Format("{0} - {1}", this.Feature, this.Name); } public static implicit operator OptionKey(Option option) { return new OptionKey(option); } } }