From 92662c1b419414ac260f055d29db7af9de2ffceb Mon Sep 17 00:00:00 2001 From: Victor Irzak Date: Thu, 28 Dec 2023 07:41:11 -0500 Subject: [PATCH] Use this.options, move options to the misc region, remove RefreshProperties attribute --- .../DocumentProcessors/CDATADocumentProcessor.cs | 2 +- .../DocumentProcessors/CommentDocumentProcessor.cs | 8 ++++---- .../DocumentProcessors/ElementDocumentProcessor.cs | 6 +++--- .../DocumentProcessors/EndElementDocumentProcessor.cs | 2 +- .../ProcessInstructionDocumentProcessor.cs | 2 +- .../SignificantWhitespaceDocumentProcessor.cs | 2 +- .../DocumentProcessors/TextDocumentProcessor.cs | 4 ++-- .../DocumentProcessors/WhitespaceDocumentProcessor.cs | 4 ++-- src/XamlStyler/Options/IStylerOptions.cs | 8 ++++---- src/XamlStyler/Options/StylerOptions.cs | 2 -- src/XamlStyler/StylerService.cs | 10 +++++----- 11 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/XamlStyler/DocumentProcessors/CDATADocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/CDATADocumentProcessor.cs index 4570a51e..49f06d66 100644 --- a/src/XamlStyler/DocumentProcessors/CDATADocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/CDATADocumentProcessor.cs @@ -43,7 +43,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon // http://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends // Change them back into the environment newline characters. output.Append(""); } } diff --git a/src/XamlStyler/DocumentProcessors/CommentDocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/CommentDocumentProcessor.cs index 0eeaab1a..d70951f9 100644 --- a/src/XamlStyler/DocumentProcessors/CommentDocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/CommentDocumentProcessor.cs @@ -31,7 +31,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon if ((output.Length > 0) && !output.IsNewLine()) { - output.Append(options.NewLine); + output.Append(this.options.NewLine); } if (content.Contains("<") && content.Contains(">")) @@ -41,7 +41,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon if (content.Contains("\n")) { - output.Append(String.Join(options.NewLine, content.GetLines().Select(_ => _.TrimEnd(' ')))); + output.Append(String.Join(this.options.NewLine, content.GetLines().Select(_ => _.TrimEnd(' ')))); if (content.TrimEnd(' ').EndsWith("\n", StringComparison.Ordinal)) { @@ -66,10 +66,10 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon var contentIndentString = this.indentService.GetIndentString(xmlReader.Depth + 1); foreach (var line in content.Trim().GetLines()) { - output.Append(options.NewLine).Append(contentIndentString).Append(line.Trim()); + output.Append(this.options.NewLine).Append(contentIndentString).Append(line.Trim()); } - output.Append(options.NewLine).Append(currentIndentString).Append("-->"); + output.Append(this.options.NewLine).Append(currentIndentString).Append("-->"); } else { diff --git a/src/XamlStyler/DocumentProcessors/ElementDocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/ElementDocumentProcessor.cs index fa209e30..85cedf1f 100644 --- a/src/XamlStyler/DocumentProcessors/ElementDocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/ElementDocumentProcessor.cs @@ -87,7 +87,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon } else { - output.Append(options.NewLine).Append(currentIndentString); + output.Append(this.options.NewLine).Append(currentIndentString); } } } @@ -115,7 +115,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon if (putEndingBracketOnNewLine) { // Indent ending bracket just like an attribute. - output.Append(options.NewLine).Append(attributeIndetationString); + output.Append(this.options.NewLine).Append(attributeIndetationString); } if (isEmptyElement) @@ -302,7 +302,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon } else { - output.Append(options.NewLine) + output.Append(this.options.NewLine) .Append(this.indentService.Normalize(attributeIndentationString + attributeLines[i].Trim())); } } diff --git a/src/XamlStyler/DocumentProcessors/EndElementDocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/EndElementDocumentProcessor.cs index 3b37993e..724926b5 100644 --- a/src/XamlStyler/DocumentProcessors/EndElementDocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/EndElementDocumentProcessor.cs @@ -67,7 +67,7 @@ public EndElementDocumentProcessor(IStylerOptions options, IndentService indentS if (!output.IsNewLine()) { - output.Append(options.NewLine); + output.Append(this.options.NewLine); } output.Append(currentIndentString).Append(""); diff --git a/src/XamlStyler/DocumentProcessors/ProcessInstructionDocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/ProcessInstructionDocumentProcessor.cs index 8852923b..c5cf4c90 100644 --- a/src/XamlStyler/DocumentProcessors/ProcessInstructionDocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/ProcessInstructionDocumentProcessor.cs @@ -29,7 +29,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon if (!output.IsNewLine()) { - output.Append(options.NewLine); + output.Append(this.options.NewLine); } output.Append($"{currentIndentString}"); diff --git a/src/XamlStyler/DocumentProcessors/SignificantWhitespaceDocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/SignificantWhitespaceDocumentProcessor.cs index 6d2ba970..ab9efbbc 100644 --- a/src/XamlStyler/DocumentProcessors/SignificantWhitespaceDocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/SignificantWhitespaceDocumentProcessor.cs @@ -20,7 +20,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon // All newlines are returned by XmlReader as '\n' due to requirements in the XML Specification. // http://www.w3.org/TR/2008/REC-xml-20081126/#sec-line-ends // Change them back into the environment newline characters. - output.Append(xmlReader.Value.Replace("\n", options.NewLine)); + output.Append(xmlReader.Value.Replace("\n", this.options.NewLine)); } } } \ No newline at end of file diff --git a/src/XamlStyler/DocumentProcessors/TextDocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/TextDocumentProcessor.cs index 63e670b7..5380fef7 100644 --- a/src/XamlStyler/DocumentProcessors/TextDocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/TextDocumentProcessor.cs @@ -30,7 +30,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon var xmlEncodedContent = xmlReader.Value.ToXmlEncodedString(ignoreCarrier: true); if (elementProcessContext.Current.IsPreservingSpace) { - output.Append(xmlEncodedContent.Replace("\n", options.NewLine)); + output.Append(xmlEncodedContent.Replace("\n", this.options.NewLine)); } else { @@ -45,7 +45,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon var trimmedLine = line.Trim(); if (trimmedLine.Length > 0) { - output.Append(options.NewLine).Append(currentIndentString).Append(trimmedLine); + output.Append(this.options.NewLine).Append(currentIndentString).Append(trimmedLine); } } } diff --git a/src/XamlStyler/DocumentProcessors/WhitespaceDocumentProcessor.cs b/src/XamlStyler/DocumentProcessors/WhitespaceDocumentProcessor.cs index 81024658..79cb99f1 100644 --- a/src/XamlStyler/DocumentProcessors/WhitespaceDocumentProcessor.cs +++ b/src/XamlStyler/DocumentProcessors/WhitespaceDocumentProcessor.cs @@ -35,7 +35,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon .Replace(" ", String.Empty) .Replace("\t", String.Empty) .Replace("\r", String.Empty) - .Replace("\n", options.NewLine)); + .Replace("\n", this.options.NewLine)); } else { @@ -46,7 +46,7 @@ public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessCon // B // // - output.Append(xmlReader.Value.Replace("\n", options.NewLine)); + output.Append(xmlReader.Value.Replace("\n", this.options.NewLine)); } } } diff --git a/src/XamlStyler/Options/IStylerOptions.cs b/src/XamlStyler/Options/IStylerOptions.cs index 75c0a11b..582a445b 100644 --- a/src/XamlStyler/Options/IStylerOptions.cs +++ b/src/XamlStyler/Options/IStylerOptions.cs @@ -107,6 +107,10 @@ public interface IStylerOptions int CommentSpaces { get; set; } + string NewLine { get; } + + string EndOfLine { get; set; } + #endregion Misc #region Configuration @@ -119,10 +123,6 @@ public interface IStylerOptions bool SuppressProcessing { get; set; } - string NewLine { get; } - - string EndOfLine { get; set; } - #endregion Configuration } } \ No newline at end of file diff --git a/src/XamlStyler/Options/StylerOptions.cs b/src/XamlStyler/Options/StylerOptions.cs index 92d52e4d..1cedb298 100644 --- a/src/XamlStyler/Options/StylerOptions.cs +++ b/src/XamlStyler/Options/StylerOptions.cs @@ -359,7 +359,6 @@ public string ConfigPath private string endOfLine; [Category("Misc")] - [RefreshProperties(RefreshProperties.All)] [Description("Defines end of line character. Specify 'lf' or 'crlf'; otherwise, default character of the host will be used.")] [JsonProperty("EndOfLine", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] [DefaultValue("")] @@ -378,7 +377,6 @@ public string EndOfLine [JsonIgnore] public string NewLine { get; private set; } = Environment.NewLine; - /// /// Creates a clone from the current instance. /// diff --git a/src/XamlStyler/StylerService.cs b/src/XamlStyler/StylerService.cs index c142c3bc..517501b1 100644 --- a/src/XamlStyler/StylerService.cs +++ b/src/XamlStyler/StylerService.cs @@ -90,18 +90,18 @@ private void ApplyOptions(IList ignoredNamespacesPrefixes, bool ignoreDe // { XmlNodeType.None, null }, { XmlNodeType.Element, new ElementDocumentProcessor(options, xamlLanguageOptions, attributeInfoFactory, attributeInfoFormatter, indentService, xmlEscapingService) }, // { XmlNodeType.Attribute, null }, - { XmlNodeType.Text, new TextDocumentProcessor(options, indentService) }, - { XmlNodeType.CDATA, new CDATADocumentProcessor(options, indentService) }, + { XmlNodeType.Text, new TextDocumentProcessor(this.options, indentService) }, + { XmlNodeType.CDATA, new CDATADocumentProcessor(this.options, indentService) }, // { XmlNodeType.EntityReference, null }, // { XmlNodeType.Entity, null }, - { XmlNodeType.ProcessingInstruction, new ProcessInstructionDocumentProcessor(options, indentService) }, + { XmlNodeType.ProcessingInstruction, new ProcessInstructionDocumentProcessor(this.options, indentService) }, { XmlNodeType.Comment, new CommentDocumentProcessor(options, indentService) }, // { XmlNodeType.Document, null }, // { XmlNodeType.DocumentType, null }, // { XmlNodeType.DocumentFragment, null }, // { XmlNodeType.Notation, null }, - { XmlNodeType.Whitespace, new WhitespaceDocumentProcessor(options) }, - { XmlNodeType.SignificantWhitespace, new SignificantWhitespaceDocumentProcessor(options) }, + { XmlNodeType.Whitespace, new WhitespaceDocumentProcessor(this.options) }, + { XmlNodeType.SignificantWhitespace, new SignificantWhitespaceDocumentProcessor(this.options) }, { XmlNodeType.EndElement, new EndElementDocumentProcessor(options, indentService) }, // { XmlNodeType.EndEntity, null }, // ignoring xml declarations for Xamarin support