From b115aa074511ea5662c9df7e636b86b8b0556066 Mon Sep 17 00:00:00 2001 From: Vaughan Woodzell Date: Fri, 10 May 2013 17:42:33 -0600 Subject: [PATCH 1/2] Always format properties as elements when they follow other elements. --- .../XmlBamlReader.cs | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index 90b0d95ba..6a16e0482 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -908,11 +908,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection short identifier = reader.ReadInt16(); string text = reader.ReadString(); - PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); - XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd); - property.Value = text; - - nodes.Enqueue(property); + EnqueueProperty(identifier, text); } void ReadPropertyWithConverter() @@ -921,11 +917,41 @@ namespace Ricciolo.StylesExplorer.MarkupReflection string text = reader.ReadString(); reader.ReadInt16(); + EnqueueProperty(identifier, text); + } + + bool HaveSeenNestedElement() + { + XmlBamlElement element = elements.Peek(); + int elementIndex = nodes.IndexOf(element); + for (int i = elementIndex + 1; i < nodes.Count; i++) + { + if (nodes[i] is XmlBamlEndElement) + return true; + } + return false; + } + + void EnqueueProperty(short identifier, string text) + { PropertyDeclaration pd = this.GetPropertyDeclaration(identifier); - XmlBamlProperty property = new XmlBamlProperty(elements.Peek(), PropertyType.Value, pd); - property.Value = text; - - nodes.Enqueue(property); + XmlBamlElement element = FindXmlBamlElement(); + // if we've already read a nested element for the current element, this property must be a nested element as well + if (HaveSeenNestedElement()) + { + XmlBamlPropertyElement property = new XmlBamlPropertyElement(element, PropertyType.Complex, pd); + + nodes.Enqueue(property); + nodes.Enqueue(new XmlBamlText(text)); + nodes.Enqueue(new XmlBamlEndElement(property)); + } + else + { + XmlBamlProperty property = new XmlBamlProperty(element, PropertyType.Value, pd); + property.Value = text; + + nodes.Enqueue(property); + } } void ReadAttributeInfo() From c0c47244d8bbde0a1923e8fe7066f0a2ee1e440a Mon Sep 17 00:00:00 2001 From: Vaughan Woodzell Date: Fri, 10 May 2013 18:37:02 -0600 Subject: [PATCH 2/2] Test case for formatting simple properties as elements when following other elements. --- ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml | 6 ++++++ .../Tests/ILSpy.BamlDecompiler.Tests.csproj | 1 + ILSpy.BamlDecompiler/Tests/TestRunner.cs | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml diff --git a/ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml b/ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml new file mode 100644 index 000000000..becbf4713 --- /dev/null +++ b/ILSpy.BamlDecompiler/Tests/Cases/SimplePropertyElement.xaml @@ -0,0 +1,6 @@ +