/
PerLanguageOption.cs
90 lines (66 loc) · 3.44 KB
/
PerLanguageOption.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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.
using System;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.Options
{
/// <inheritdoc cref="PerLanguageOption2{T}"/>
public class PerLanguageOption<T> : IPerLanguageOption<T>
{
private readonly OptionDefinition _optionDefinition;
/// <inheritdoc cref="OptionDefinition.Feature"/>
public string Feature => _optionDefinition.Feature;
/// <inheritdoc cref="OptionDefinition.Group"/>
internal OptionGroup Group => _optionDefinition.Group;
/// <inheritdoc cref="OptionDefinition.Name"/>
public string Name => _optionDefinition.Name;
/// <inheritdoc cref="OptionDefinition.Type"/>
public Type Type => _optionDefinition.Type;
/// <inheritdoc cref="OptionDefinition.DefaultValue"/>
public T DefaultValue => (T)_optionDefinition.DefaultValue!;
/// <inheritdoc cref="PerLanguageOption2{T}.StorageLocations"/>
public ImmutableArray<OptionStorageLocation> StorageLocations { get; }
public PerLanguageOption(string feature, string name, T defaultValue)
: this(feature, name, defaultValue, storageLocations: ImmutableArray<OptionStorageLocation>.Empty)
{
}
public PerLanguageOption(string feature, string name, T defaultValue, params OptionStorageLocation[] storageLocations)
: this(feature, group: OptionGroup.Default, name, defaultValue, storageLocations.ToImmutableArray())
{
}
internal PerLanguageOption(string feature, string name, T defaultValue, OptionStorageLocation storageLocation)
: this(feature, name, defaultValue, storageLocations: ImmutableArray.Create(storageLocation))
{
}
internal PerLanguageOption(string feature, string name, T defaultValue, ImmutableArray<OptionStorageLocation> storageLocations)
: this(feature, OptionGroup.Default, name, defaultValue, storageLocations)
{
}
internal PerLanguageOption(string feature, OptionGroup group, string name, T defaultValue, ImmutableArray<OptionStorageLocation> storageLocations)
: this(new OptionDefinition(feature, group, name, defaultValue, typeof(T), isPerLanguage: true), storageLocations)
{
}
internal PerLanguageOption(OptionDefinition optionDefinition, ImmutableArray<OptionStorageLocation> storageLocations)
{
_optionDefinition = optionDefinition;
StorageLocations = storageLocations;
}
OptionDefinition IOption2.OptionDefinition => _optionDefinition;
OptionGroup IOptionWithGroup.Group => this.Group;
object? IOption.DefaultValue => this.DefaultValue;
bool IOption.IsPerLanguage => true;
bool IEquatable<IOption2?>.Equals(IOption2? other) => Equals(other);
public override string ToString() => _optionDefinition.ToString();
public override int GetHashCode() => _optionDefinition.GetHashCode();
public override bool Equals(object? obj) => Equals(obj as IOption2);
private bool Equals(IOption2? other)
{
if (ReferenceEquals(this, other))
{
return true;
}
return _optionDefinition == other?.OptionDefinition;
}
}
}