-
Notifications
You must be signed in to change notification settings - Fork 4k
/
PerLanguageOption.cs
87 lines (70 loc) · 2.7 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
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Diagnostics;
namespace Microsoft.CodeAnalysis.Options
{
/// <summary>
/// An option that can be specified once per language.
/// </summary>
/// <typeparam name="T"></typeparam>
public class PerLanguageOption<T> : IOptionWithGroup
{
/// <summary>
/// Feature this option is associated with.
/// </summary>
public string Feature { get; }
/// <summary>
/// Optional group/sub-feature for this option.
/// </summary>
internal OptionGroup Group { get; }
/// <summary>
/// The name of the option.
/// </summary>
public string Name { get; }
/// <summary>
/// The type of the option value.
/// </summary>
public Type Type => typeof(T);
/// <summary>
/// The default option value.
/// </summary>
public T DefaultValue { get; }
public ImmutableArray<OptionStorageLocation> StorageLocations { get; }
public PerLanguageOption(string feature, string name, T defaultValue)
: this(feature, name, defaultValue, storageLocations: Array.Empty<OptionStorageLocation>())
{
}
public PerLanguageOption(string feature, string name, T defaultValue, params OptionStorageLocation[] storageLocations)
: this(feature, group: OptionGroup.Default, name, defaultValue, storageLocations)
{
}
internal PerLanguageOption(string feature, OptionGroup group, string name, T defaultValue, params OptionStorageLocation[] storageLocations)
{
if (string.IsNullOrWhiteSpace(feature))
{
throw new ArgumentNullException(nameof(feature));
}
if (group == null)
{
throw new ArgumentNullException(nameof(group));
}
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException(nameof(name));
}
this.Feature = feature;
this.Group = group;
this.Name = name;
this.DefaultValue = defaultValue;
this.StorageLocations = storageLocations.ToImmutableArray();
}
object IOption.DefaultValue => this.DefaultValue;
bool IOption.IsPerLanguage => true;
OptionGroup IOptionWithGroup.Group => this.Group;
public override string ToString()
{
return string.Format("{0} - {1}", this.Feature, this.Name);
}
}
}