private bool IsDiagnosticSuppressed(string id, Location location, out SuppressMessageInfo info) { Debug.Assert(id != null); Debug.Assert(location != null); info = default(SuppressMessageInfo); if (IsDiagnosticGloballySuppressed(id, symbolOpt: null, info: out info)) { return(true); } // Walk up the syntax tree checking for suppression by any declared symbols encountered if (location.IsInSource) { SemanticModel model = _compilation.GetSemanticModel(location.SourceTree); bool inImmediatelyContainingSymbol = true; for (SyntaxNode node = location.SourceTree.GetRoot().FindNode(location.SourceSpan, getInnermostNodeForTie: true); node != null; node = node.Parent) { ImmutableArray <ISymbol> declaredSymbols = model.GetDeclaredSymbolsForNode(node); Debug.Assert(declaredSymbols != null); foreach (ISymbol symbol in declaredSymbols) { if (symbol.Kind == SymbolKind.Namespace) { // Special case: Only suppress syntax diagnostics in namespace declarations if the namespace is the closest containing symbol. // In other words, only apply suppression to the immediately containing namespace declaration and not to its children or parents. return(inImmediatelyContainingSymbol && IsDiagnosticGloballySuppressed(id, symbol, out info)); } else if (IsDiagnosticLocallySuppressed(id, symbol, out info) || IsDiagnosticGloballySuppressed(id, symbol, out info)) { return(true); } inImmediatelyContainingSymbol = false; } } } return(false); }