/
DocumentOptionSet.cs
43 lines (36 loc) · 1.66 KB
/
DocumentOptionSet.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
// 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.Collections.Generic;
namespace Microsoft.CodeAnalysis.Options
{
/// <summary>
/// An <see cref="OptionSet"/> that comes from <see cref="Document.GetOptionsAsync(System.Threading.CancellationToken)"/>. It behaves just like a normal
/// <see cref="OptionSet"/> but remembers which language the <see cref="Document"/> is, so you don't have to
/// pass that information redundantly when calling <see cref="GetOption{T}(PerLanguageOption{T})"/>.
/// </summary>
public sealed class DocumentOptionSet : OptionSet
{
private readonly OptionSet _backingOptionSet;
private readonly string _language;
internal DocumentOptionSet(OptionSet backingOptionSet, string language)
{
_backingOptionSet = backingOptionSet;
_language = language;
}
public override object GetOption(OptionKey optionKey)
{
return _backingOptionSet.GetOption(optionKey);
}
public T GetOption<T>(PerLanguageOption<T> option)
{
return _backingOptionSet.GetOption(option, _language);
}
public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object value)
{
return new DocumentOptionSet(_backingOptionSet.WithChangedOption(optionAndLanguage, value), _language);
}
internal override IEnumerable<OptionKey> GetChangedOptions(OptionSet optionSet)
{
return _backingOptionSet.GetChangedOptions(optionSet);
}
}
}