diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs index de28960da246e3758fd5174ca32de994873c1b60..2fd6e9fc059897b938b935e205a29d3a8e3135bd 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerConfigOptions.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; @@ -22,11 +23,6 @@ public abstract class AnalyzerConfigOptions /// Get an analyzer config value for the given key, using the . /// public abstract bool TryGetValue(string key, out string value); - - /// - /// Get the keys of the defined options. - /// - public abstract IEnumerable Keys { get; } } internal sealed class CompilerAnalyzerConfigOptions : AnalyzerConfigOptions @@ -41,7 +37,5 @@ public CompilerAnalyzerConfigOptions(ImmutableDictionary propert } public override bool TryGetValue(string key, out string value) => _backing.TryGetValue(key, out value); - - public override IEnumerable Keys => _backing.Keys; } } diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index 1050be2d7662b955e45c52cbd95b3fdc3234f478..d76a01da73e02821920f3a36f3c894d9596cb5e1 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -21,7 +21,6 @@ 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 -abstract Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptions.Keys.get -> System.Collections.Generic.IEnumerable 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 diff --git a/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs b/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs index 5abc812cba2cf8d6d834b9d24f707d32bf89d4ba..5423c11c4e401904a352ea5aedcd8ea586e69a40 100644 --- a/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs +++ b/src/Workspaces/Core/Portable/Options/EditorConfig/EditorConfigStorageLocationExtensions.cs @@ -1,9 +1,8 @@ // 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.Collections.Generic; using Microsoft.CodeAnalysis.Diagnostics; -using Roslyn.Collections.Immutable; namespace Microsoft.CodeAnalysis.Options { @@ -11,15 +10,17 @@ internal static class EditorConfigStorageLocationExtensions { public static bool TryGetOption(this IEditorConfigStorageLocation editorConfigStorageLocation, AnalyzerConfigOptions analyzerConfigOptions, Type type, out object value) { - var optionDictionary = analyzerConfigOptions.Keys.ToImmutableDictionary( - key => key, - key => - { - analyzerConfigOptions.TryGetValue(key, out var optionValue); - return optionValue; - }); + // This is a workaround until we have an API for enumeratings AnalyzerConfigOptions. + var backingField = analyzerConfigOptions.GetType().GetField("_backing", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + var backing = backingField?.GetValue(analyzerConfigOptions); - return editorConfigStorageLocation.TryGetOption(optionDictionary, type, out value); + if (backing is IReadOnlyDictionary backingDictionary) + { + return editorConfigStorageLocation.TryGetOption(backingDictionary, type, out value); + } + + value = null; + return false; } } } diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs index e45f3f0b04c3501d053f00d63d382a4e31d9a0a0..962eb68f1a9859a2578627b7b21686b4d24dfdd9 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/ProjectState.cs @@ -319,8 +319,6 @@ public WorkspaceAnalyzerConfigOptions(AnalyzerConfigOptionsResult analyzerConfig } public override bool TryGetValue(string key, out string value) => _backing.TryGetValue(key, out value); - - public override IEnumerable Keys => _backing.Keys; } }