예제 #1
0
 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)));
 }
예제 #2
0
        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);
        }
예제 #3
0
        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));
        }
예제 #4
0
        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);
        }
예제 #5
0
 internal bool ContainsMessage(SuppressMessage message) => Messages.Contains(message);
예제 #6
0
 internal void AddMessage(SuppressMessage message) => Messages.Add(message);
예제 #7
0
 internal void AddMessage(SuppressMessage message) => Messages.TryAdd(message, null);