提交 b668b923 编写于 作者: J Joey Robichaud

Add a way to enumerate AnalyzerConfigOption keys

上级 6cfe97dc
......@@ -22,29 +22,26 @@ public abstract class AnalyzerConfigOptions
/// Get an analyzer config value for the given key, using the <see cref="KeyComparer"/>.
/// </summary>
public abstract bool TryGetValue(string key, out string value);
/// <summary>
/// Get the keys of the defined options.
/// </summary>
public abstract ImmutableArray<string> Keys { get; }
}
public abstract class DictionaryBackedAnalyzerConfigOptions : AnalyzerConfigOptions
internal sealed class CompilerAnalyzerConfigOptions : AnalyzerConfigOptions
{
public static CompilerAnalyzerConfigOptions Empty { get; } = new CompilerAnalyzerConfigOptions(EmptyDictionary);
private readonly ImmutableDictionary<string, string> _backing;
public DictionaryBackedAnalyzerConfigOptions(ImmutableDictionary<string, string> properties)
public CompilerAnalyzerConfigOptions(ImmutableDictionary<string, string> properties)
{
_backing = properties;
}
public override bool TryGetValue(string key, out string value) => _backing.TryGetValue(key, out value);
public IReadOnlyDictionary<string, string> AsReadOnlyDictionary() => _backing;
}
internal sealed class CompilerAnalyzerConfigOptions : DictionaryBackedAnalyzerConfigOptions
{
public static CompilerAnalyzerConfigOptions Empty { get; } = new CompilerAnalyzerConfigOptions(EmptyDictionary);
public CompilerAnalyzerConfigOptions(ImmutableDictionary<string, string> properties)
: base(properties)
{
}
public override ImmutableArray<string> Keys => _backing.Keys.ToImmutableArray();
}
}
Microsoft.CodeAnalysis.CommandLineArguments.ErrorLogOptions.get -> Microsoft.CodeAnalysis.ErrorLogOptions
*REMOVED*Microsoft.CodeAnalysis.CommandLineArguments.ErrorLogPath.get -> string
Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions
Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions.AsReadOnlyDictionary() -> System.Collections.Generic.IReadOnlyDictionary<string, string>
Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions.DictionaryBackedAnalyzerConfigOptions(System.Collections.Immutable.ImmutableDictionary<string, string> properties) -> void
Microsoft.CodeAnalysis.ErrorLogOptions
Microsoft.CodeAnalysis.ErrorLogOptions.ErrorLogOptions(string path, Microsoft.CodeAnalysis.SarifVersion sarifVersion) -> void
Microsoft.CodeAnalysis.ErrorLogOptions.Path.get -> string
......@@ -22,7 +19,7 @@ Microsoft.CodeAnalysis.SarifVersion.Latest = 2147483647 -> Microsoft.CodeAnalysi
Microsoft.CodeAnalysis.SarifVersion.Sarif1 = 1 -> Microsoft.CodeAnalysis.SarifVersion
Microsoft.CodeAnalysis.SarifVersion.Sarif2 = 2 -> Microsoft.CodeAnalysis.SarifVersion
Microsoft.CodeAnalysis.SarifVersionFacts
override Microsoft.CodeAnalysis.Diagnostics.DictionaryBackedAnalyzerConfigOptions.TryGetValue(string key, out string value) -> bool
abstract Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptions.Keys.get -> System.Collections.Immutable.ImmutableArray<string>
Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier = 256 -> Microsoft.CodeAnalysis.SymbolDisplayMiscellaneousOptions
static Microsoft.CodeAnalysis.SarifVersionFacts.TryParse(string version, out Microsoft.CodeAnalysis.SarifVersion result) -> bool
Microsoft.CodeAnalysis.IMethodSymbol.IsConditional.get -> bool
......
// 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;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Diagnostics;
using Roslyn.Collections.Immutable;
namespace Microsoft.CodeAnalysis.Options
{
......@@ -11,63 +11,15 @@ internal static class EditorConfigStorageLocationExtensions
{
public static bool TryGetOption(this IEditorConfigStorageLocation editorConfigStorageLocation, AnalyzerConfigOptions analyzerConfigOptions, Type type, out object value)
{
var optionDictionary = analyzerConfigOptions is DictionaryBackedAnalyzerConfigOptions dictionaryAnalyzerConfigOptions
? dictionaryAnalyzerConfigOptions.AsReadOnlyDictionary()
: new AnalyzerConfigOptionsDictionary(analyzerConfigOptions);
return editorConfigStorageLocation.TryGetOption(optionDictionary, type, out value);
}
/// <summary>
/// This is a wrapper around AnalyzerConfigOptions so that it can be used as a read-only Dictionary.
/// </summary>
private class AnalyzerConfigOptionsDictionary : IReadOnlyDictionary<string, string>
{
private readonly AnalyzerConfigOptions _analyzerConfigOptions;
public AnalyzerConfigOptionsDictionary(AnalyzerConfigOptions analyzerConfigOptions)
{
_analyzerConfigOptions = analyzerConfigOptions;
}
public string this[string key]
{
get
var optionDictionary = analyzerConfigOptions.Keys.ToImmutableDictionary(
key => key,
key =>
{
if (_analyzerConfigOptions.TryGetValue(key, out var value))
{
return value;
}
throw new KeyNotFoundException();
}
}
analyzerConfigOptions.TryGetValue(key, out var optionValue);
return optionValue;
});
public IEnumerable<string> Keys => throw new NotImplementedException();
public IEnumerable<string> Values => throw new NotImplementedException();
public int Count => throw new NotImplementedException();
public bool ContainsKey(string key)
{
return _analyzerConfigOptions.TryGetValue(key, out _);
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
throw new NotImplementedException();
}
public bool TryGetValue(string key, out string value)
{
return _analyzerConfigOptions.TryGetValue(key, out value);
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
return editorConfigStorageLocation.TryGetOption(optionDictionary, type, out value);
}
}
}
......@@ -307,12 +307,18 @@ public override AnalyzerConfigOptions GetOptions(AdditionalText textFile)
}
// PROTOTYPE: why isn't this just a provided implementation?
private sealed class WorkspaceAnalyzerConfigOptions : DictionaryBackedAnalyzerConfigOptions
private sealed class WorkspaceAnalyzerConfigOptions : AnalyzerConfigOptions
{
private readonly ImmutableDictionary<string, string> _backing;
public WorkspaceAnalyzerConfigOptions(AnalyzerConfigOptionsResult analyzerConfigOptions)
: base(analyzerConfigOptions.AnalyzerOptions)
{
_backing = analyzerConfigOptions.AnalyzerOptions;
}
public override bool TryGetValue(string key, out string value) => _backing.TryGetValue(key, out value);
public override ImmutableArray<string> Keys => _backing.Keys.ToImmutableArray();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册