diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/SuppressMessageAttributeState.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/SuppressMessageAttributeState.cs index 4a9c1753b85d4b33676009e755a92a17b556ec11..f6c5786a25b933dfd465c201ac990e71d57e88a1 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/SuppressMessageAttributeState.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/SuppressMessageAttributeState.cs @@ -1,5 +1,6 @@ // 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.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; @@ -12,9 +13,9 @@ namespace Microsoft.CodeAnalysis.Diagnostics { internal partial class SuppressMessageAttributeState { - private static readonly SmallDictionary s_suppressMessageScopeTypes = new SmallDictionary() + private static readonly SmallDictionary s_suppressMessageScopeTypes = new SmallDictionary(StringComparer.OrdinalIgnoreCase) { - { null, TargetScope.None }, + { string.Empty, TargetScope.None }, { "module", TargetScope.Module }, { "namespace", TargetScope.Namespace }, { "resource", TargetScope.Resource }, @@ -24,10 +25,7 @@ internal partial class SuppressMessageAttributeState }; private static bool TryGetTargetScope(SuppressMessageInfo info, out TargetScope scope) - { - string scopeString = info.Scope != null ? info.Scope.ToLowerInvariant() : null; - return s_suppressMessageScopeTypes.TryGetValue(scopeString, out scope); - } + => s_suppressMessageScopeTypes.TryGetValue(info.Scope ?? string.Empty, out scope); private readonly Compilation _compilation; private GlobalSuppressions _lazyGlobalSuppressions; @@ -170,7 +168,10 @@ private bool IsDiagnosticSuppressed(string id, Location location, out SuppressMe { return true; } + } + if (!declaredSymbols.IsEmpty) + { inImmediatelyContainingSymbol = false; } } diff --git a/src/Test/Utilities/Portable/Diagnostics/SuppressMessageAttributeTests.cs b/src/Test/Utilities/Portable/Diagnostics/SuppressMessageAttributeTests.cs index 560fad0e9c22f3b3a1910fa2e513a8b547ec4cf3..c134ec7a6c860fc8505903cc6b8373b79465ff5b 100644 --- a/src/Test/Utilities/Portable/Diagnostics/SuppressMessageAttributeTests.cs +++ b/src/Test/Utilities/Portable/Diagnostics/SuppressMessageAttributeTests.cs @@ -117,7 +117,7 @@ public async Task GlobalSuppressionOnNamespaces_NamespaceAndChildren() using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage(""Test"", ""Declaration"", Scope=""NamespaceAndChildren"", Target=""N.N1"")] -[module: SuppressMessage(""Test"", ""Declaration"", Scope=""NamespaceAndChildren"", Target=""N4"")] +[module: SuppressMessage(""Test"", ""Declaration"", Scope=""namespaceandchildren"", Target=""N4"")] namespace N {