diff --git a/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatter.cs b/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatter.cs index 4ed37747..b5abba81 100644 --- a/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatter.cs +++ b/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatter.cs @@ -9,12 +9,15 @@ namespace Xavalon.XamlStyler.Core.MarkupExtensions.Formatter public class MarkupExtensionFormatter { private readonly IList singleLineTypes; - private readonly MarkupExtensionFormatterBase singleLineFormatter = new SingleLineMarkupExtensionFormatter(); - private readonly MarkupExtensionFormatterBase multiLineFormatter = new MultiLineMarkupExtensionFormatter(); + private readonly MarkupExtensionFormatterBase singleLineFormatter; + private readonly MarkupExtensionFormatterBase multiLineFormatter; public MarkupExtensionFormatter(IList singleLineTypes) { this.singleLineTypes = singleLineTypes; + + this.singleLineFormatter = new SingleLineMarkupExtensionFormatter(this); + this.multiLineFormatter = new MultiLineMarkupExtensionFormatter(this); } /// diff --git a/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatterBase.cs b/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatterBase.cs index 7465e875..8f93a9c3 100644 --- a/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatterBase.cs +++ b/XamlStyler.Core/MarkupExtensions/Formatter/MarkupExtensionFormatterBase.cs @@ -9,6 +9,13 @@ namespace Xavalon.XamlStyler.Core.MarkupExtensions.Formatter { internal abstract class MarkupExtensionFormatterBase { + protected readonly MarkupExtensionFormatter markupExtensionFormatter; + + protected MarkupExtensionFormatterBase(MarkupExtensionFormatter markupExtensionFormatter) + { + this.markupExtensionFormatter = markupExtensionFormatter; + } + public IEnumerable Format(MarkupExtension markupExtension) { return markupExtension.Arguments.Any() @@ -29,7 +36,16 @@ protected IEnumerable Format(Argument argument) if (type == typeof(PositionalArgument)) { - return this.Format((PositionalArgument)argument); + var positionalArgument = (PositionalArgument)argument; + + if (positionalArgument.Value.GetType() == typeof(MarkupExtension)) + { + return this.markupExtensionFormatter.Format((MarkupExtension)positionalArgument.Value); + } + else + { + return this.Format(positionalArgument); + } } throw new ArgumentException($"Unhandled type {type.FullName}", nameof(argument)); diff --git a/XamlStyler.Core/MarkupExtensions/Formatter/MultiLineMarkupExtensionFormatter.cs b/XamlStyler.Core/MarkupExtensions/Formatter/MultiLineMarkupExtensionFormatter.cs index e48392f9..a1b910c2 100644 --- a/XamlStyler.Core/MarkupExtensions/Formatter/MultiLineMarkupExtensionFormatter.cs +++ b/XamlStyler.Core/MarkupExtensions/Formatter/MultiLineMarkupExtensionFormatter.cs @@ -7,6 +7,11 @@ namespace Xavalon.XamlStyler.Core.MarkupExtensions.Formatter { internal class MultiLineMarkupExtensionFormatter : MarkupExtensionFormatterBase { + internal MultiLineMarkupExtensionFormatter(MarkupExtensionFormatter markupExtensionFormatter) + : base(markupExtensionFormatter) + { + } + protected override IEnumerable Format(Argument[] arguments) { var list = new List(); diff --git a/XamlStyler.Core/MarkupExtensions/Formatter/SingleLineMarkupExtensionFormatter.cs b/XamlStyler.Core/MarkupExtensions/Formatter/SingleLineMarkupExtensionFormatter.cs index 2188f1ca..a6298644 100644 --- a/XamlStyler.Core/MarkupExtensions/Formatter/SingleLineMarkupExtensionFormatter.cs +++ b/XamlStyler.Core/MarkupExtensions/Formatter/SingleLineMarkupExtensionFormatter.cs @@ -8,6 +8,11 @@ namespace Xavalon.XamlStyler.Core.MarkupExtensions.Formatter { internal class SingleLineMarkupExtensionFormatter : MarkupExtensionFormatterBase { + internal SingleLineMarkupExtensionFormatter(MarkupExtensionFormatter markupExtensionFormatter) + : base(markupExtensionFormatter) + { + } + protected override IEnumerable Format(Argument[] arguments) { StringBuilder stringBuilder = new StringBuilder(); diff --git a/XamlStyler.Core/MarkupExtensions/Parser/MarkupExtension.cs b/XamlStyler.Core/MarkupExtensions/Parser/MarkupExtension.cs index aed9d305..0b9b32fa 100644 --- a/XamlStyler.Core/MarkupExtensions/Parser/MarkupExtension.cs +++ b/XamlStyler.Core/MarkupExtensions/Parser/MarkupExtension.cs @@ -64,7 +64,7 @@ private static IEnumerable GetArguments(IEnumerable nod else { // Unwrap argument. - foreach (var markupExtensionArgument in GetArguments(node.ChildNodes)) + foreach (var markupExtensionArgument in MarkupExtension.GetArguments(node.ChildNodes)) { yield return markupExtensionArgument; } diff --git a/XamlStyler.UnitTests/FileHandlingIntegrationTests.cs b/XamlStyler.UnitTests/FileHandlingIntegrationTests.cs index 8491ce48..0f31acae 100644 --- a/XamlStyler.UnitTests/FileHandlingIntegrationTests.cs +++ b/XamlStyler.UnitTests/FileHandlingIntegrationTests.cs @@ -174,6 +174,20 @@ public void TestMarkupExtensionHandling(bool indentWithTabs, int tabSize) this.DoTestCase(stylerOptions, $"{tabSize}_{(indentWithTabs ? "tabs" : "spaces")}"); } + [Test] + public void TestNestedCustomMarkupExtensionsWithBindings() + { + var stylerOptions = new StylerOptions( + config: this.GetConfiguration(@"TestConfigurations\LegacyTestSettings.json")) + { + KeepFirstAttributeOnSameLine = false, + AttributesTolerance = 1, + NoNewLineMarkupExtensions = "x:Bind, Binding" + }; + + this.DoTest(stylerOptions); + } + [Test] public void TestMarkupWithAttributeNotOnFirstLine() { diff --git a/XamlStyler.UnitTests/TestFiles/TestNestedCustomMarkupExtensionsWithBindings.expected b/XamlStyler.UnitTests/TestFiles/TestNestedCustomMarkupExtensionsWithBindings.expected new file mode 100644 index 00000000..4a03fb2a --- /dev/null +++ b/XamlStyler.UnitTests/TestFiles/TestNestedCustomMarkupExtensionsWithBindings.expected @@ -0,0 +1,16 @@ + + +