private static XElement ElementFromMessage(SuppressMessage message) { return(new XElement(SuppressMessageElement, new XAttribute(IdAttribute, message.Id), new XElement(TargetElement, message.Target), new XElement(SyntaxNodeElement, message.SyntaxNode))); }
public static HashSet <SuppressMessage> LoadMessages(ISuppressionFileSystemService fileSystemService, string path) { XDocument document; lock (fileSystemService) { document = fileSystemService.Load(path); } if (document == null) { return(new HashSet <SuppressMessage>()); } HashSet <SuppressMessage> suppressionMessages = new HashSet <SuppressMessage>(); foreach (XElement suppressionMessageXml in document.Root.Elements(SuppressMessageElement)) { SuppressMessage?suppressMessage = SuppressMessage.MessageFromElement(suppressionMessageXml); if (suppressMessage != null) { suppressionMessages.Add(suppressMessage.Value); } } return(suppressionMessages); }
private bool IsSuppressedInSuppressionFile(SemanticModel semanticModel, Diagnostic diagnostic, CancellationToken cancellation) { cancellation.ThrowIfCancellationRequested(); var(assembly, message) = SuppressMessage.GetSuppressionInfo(semanticModel, diagnostic, cancellation); if (assembly == null) { return(false); } SuppressionFile file = GetSuppressionFile(assembly); if (file == null) { return(false); } if (file.GenerateSuppressionBase) { if (IsSuppressableSeverity(diagnostic?.Descriptor.DefaultSeverity)) { file.AddMessage(message); } return(true); } return(file.ContainsMessage(message)); }
public static bool SuppressDiagnostic(SemanticModel semanticModel, string diagnosticID, TextSpan diagnosticSpan, DiagnosticSeverity defaultDiagnosticSeverity, CancellationToken cancellation = default) { CheckIfInstanceIsInitialized(throwOnNotInitialized: true); if (!IsSuppressableSeverity(defaultDiagnosticSeverity)) { return(false); } var(fileAssemblyName, suppressMessage) = SuppressMessage.GetSuppressionInfo(semanticModel, diagnosticID, diagnosticSpan, cancellation); if (fileAssemblyName.IsNullOrWhiteSpace() || !suppressMessage.IsValid) { return(false); } lock (Instance._fileSystemService) { if (!Instance._fileByAssembly.TryGetValue(fileAssemblyName, out var file) || file == null) { return(false); } file.AddMessage(suppressMessage); XDocument newSuppressionXmlFile = file.MessagesToDocument(Instance._fileSystemService); Instance._fileSystemService.Save(newSuppressionXmlFile, file.Path); } return(true); }
internal bool ContainsMessage(SuppressMessage message) => Messages.Contains(message);
internal void AddMessage(SuppressMessage message) => Messages.Add(message);
internal void AddMessage(SuppressMessage message) => Messages.TryAdd(message, null);