Ejemplo n.º 1
0
        internal void Save(string path)
        {
            var settings = new XElement("Settings",
                                        new XElement("General",
                                                     new XElement("PrefixFieldIdentifierWithUnderscore", PrefixFieldIdentifierWithUnderscore)));

            if (Analyzers.Count > 0)
            {
                settings.Add(
                    new XElement("Analyzers",
                                 Analyzers
                                 .OrderBy(f => f.Key)
                                 .Select(f => new XElement("Analyzer", new XAttribute("Id", f.Key), new XAttribute("Value", f.Value)))
                                 ));
            }

            if (Refactorings.Any(f => !f.Value))
            {
                settings.Add(
                    new XElement("Refactorings",
                                 Refactorings
                                 .Where(f => !f.Value)
                                 .OrderBy(f => f.Key)
                                 .Select(f => new XElement("Refactoring", new XAttribute("Id", f.Key), new XAttribute("IsEnabled", f.Value)))
                                 ));
            }

            if (CodeFixes.Any(f => !f.Value))
            {
                settings.Add(
                    new XElement("CodeFixes",
                                 CodeFixes
                                 .Where(f => !f.Value)
                                 .OrderBy(f => f.Key)
                                 .Select(f => new XElement("CodeFix", new XAttribute("Id", f.Key), new XAttribute("IsEnabled", f.Value)))
                                 ));
            }

            if (RuleSets.Any())
            {
                settings.Add(
                    new XElement("RuleSets",
                                 RuleSets.Select(f => new XElement("RuleSet", new XAttribute("Path", f)))));
            }

            var doc = new XDocument(new XElement("Roslynator", settings));

            var xmlWriterSettings = new XmlWriterSettings()
            {
                OmitXmlDeclaration = false,
                NewLineChars       = Environment.NewLine,
                IndentChars        = "  ",
                Indent             = true,
            };

            using (var fileStream = new FileStream(path, FileMode.Create))
                using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
                    using (XmlWriter xmlWriter = XmlWriter.Create(streamWriter, xmlWriterSettings))
                        doc.WriteTo(xmlWriter);
        }
Ejemplo n.º 2
0
        public string CreateReadMeMarkDown()
        {
            using (var sw = new StringWriter())
            {
                sw.WriteLine(File.ReadAllText(@"..\text\ReadMe.txt", Encoding.UTF8));
                sw.WriteLine("### List of Analyzers");
                sw.WriteLine();
                foreach (AnalyzerInfo info in Analyzers
                         .OrderBy(f => f.Id, StringComparer.InvariantCulture))
                {
                    sw.WriteLine("* " + info.Id + " - " + info.Title.TrimEnd('.'));
                }

                sw.WriteLine();
                sw.WriteLine("### List of Refactorings");
                sw.WriteLine();

                foreach (RefactoringInfo info in Refactorings
                         .OrderBy(f => f.Title, StringComparer.InvariantCulture))
                {
                    sw.WriteLine("* [" + info.Title.TrimEnd('.') + "](source/Refactorings/README.md#" + info.GetGitHubHref() + ")");
                }

                return(sw.ToString());
            }
        }
Ejemplo n.º 3
0
        public string CreateAnalyzersMarkDown()
        {
            using (var sw = new StringWriter())
            {
                sw.WriteLine("## Roslynator Analyzers");
                sw.WriteLine();

                sw.WriteLine(" Id | Title | Category | Enabled by Default ");
                sw.WriteLine(" --- | --- | --- |:---:");

                foreach (AnalyzerInfo info in Analyzers.OrderBy(f => f.Id, StringComparer))
                {
                    sw.Write(info.Id);
                    sw.Write('|');
                    sw.Write(MarkdownHelper.Escape(info.Title.TrimEnd('.')));
                    sw.Write('|');
                    sw.Write(info.Category);
                    sw.Write('|');
                    sw.Write((info.IsEnabledByDefault) ? "x" : "");

                    sw.WriteLine();
                }

                return(sw.ToString());
            }
        }
Ejemplo n.º 4
0
        private void WriteAnalyzersExtensionDescription(XmlWriter xw)
        {
            xw.WriteElementString("h3", "List of Analyzers");

            xw.WriteStartElement("ul");
            foreach (AnalyzerInfo analyzer in Analyzers
                     .OrderBy(f => f.Id, StringComparer.InvariantCulture))
            {
                xw.WriteElementString("li", $"{analyzer.Id} - {analyzer.Title}");
            }

            xw.WriteEndElement();
        }