Ejemplo n.º 1
0
                // TODO: delete this once prototyping is done
                public void ChangeDiagnosticsEngine(bool useV2Engine)
                {
                    var diagnosticAnalyzer = Analyzers.FirstOrDefault(a => a is BaseDiagnosticIncrementalAnalyzer) as DiagnosticAnalyzerService.IncrementalAnalyzerDelegatee;

                    if (diagnosticAnalyzer == null)
                    {
                        return;
                    }

                    diagnosticAnalyzer.TurnOff(useV2Engine);
                }
Ejemplo n.º 2
0
        public string CreateAnalyzersXml()
        {
            FieldInfo[] fieldInfos = typeof(DiagnosticDescriptors).GetFields(BindingFlags.Public | BindingFlags.Static);

            var doc = new XDocument();

            var root = new XElement("Analyzers");

            foreach (FieldInfo fieldInfo in fieldInfos.OrderBy(f => ((DiagnosticDescriptor)f.GetValue(null)).Id))
            {
                if (fieldInfo.Name.EndsWith("FadeOut"))
                {
                    continue;
                }

                var descriptor = (DiagnosticDescriptor)fieldInfo.GetValue(null);

                AnalyzerInfo analyzer = Analyzers.FirstOrDefault(f => string.Equals(f.Id, descriptor.Id, StringComparison.CurrentCulture));

                string extensionVersion = "0.0.0";
                string nugetVersion     = "0.0.0";

                if (analyzer != null)
                {
                    extensionVersion = analyzer.ExtensionVersion;
                    nugetVersion     = analyzer.NuGetVersion;
                }

                analyzer = new AnalyzerInfo(
                    fieldInfo.Name,
                    descriptor.Title.ToString(),
                    descriptor.Id,
                    descriptor.Category,
                    descriptor.DefaultSeverity.ToString(),
                    extensionVersion,
                    nugetVersion,
                    descriptor.IsEnabledByDefault,
                    descriptor.CustomTags.Contains(WellKnownDiagnosticTags.Unnecessary),
                    fieldInfos.Any(f => f.Name == fieldInfo.Name + "FadeOut"));

                root.Add(new XElement(
                             "Analyzer",
                             new XAttribute("Identifier", analyzer.Identifier),
                             new XAttribute("ExtensionVersion", analyzer.ExtensionVersion),
                             new XAttribute("NuGetVersion", analyzer.NuGetVersion),
                             new XElement("Id", analyzer.Id),
                             new XElement("Title", analyzer.Title),
                             new XElement("Category", analyzer.Category),
                             new XElement("DefaultSeverity", analyzer.DefaultSeverity),
                             new XElement("IsEnabledByDefault", analyzer.IsEnabledByDefault),
                             new XElement("SupportsFadeOut", analyzer.SupportsFadeOut),
                             new XElement("SupportsFadeOutAnalyzer", analyzer.SupportsFadeOutAnalyzer)
                             ));
            }

            doc.Add(root);

            using (var sw = new Utf8StringWriter())
            {
                doc.Save(sw);

                return(sw.ToString());
            }
        }