From a1126ab66bc9bd41cfa32dbefbe5758bcf5b4b32 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Mon, 15 Aug 2016 22:18:26 +0200 Subject: [Xaml] Simplify listnodes with single elements (#304) --- Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs | 14 +++++++++++--- Xamarin.Forms.Xaml.UnitTests/SetValue.xaml | 9 +++++++++ Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs | 8 ++++++++ Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs | 18 +++++++++++++----- Xamarin.Forms.Xaml/XmlName.cs | 1 + 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs index b6bdf40b..5e11fe1d 100644 --- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs +++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs @@ -79,6 +79,15 @@ namespace Xamarin.Forms.Build.Tasks public void Visit(ElementNode node, INode parentNode) { + XmlName propertyName = XmlName.Empty; + + //Simplify ListNodes with single elements + var pList = parentNode as ListNode; + if (pList != null && pList.CollectionItems.Count == 1) { + propertyName = pList.XmlName; + parentNode = parentNode.Parent; + } + //if this node is an IMarkupExtension, invoke ProvideValue() and replace the variable var vardef = Context.Variables[node]; var vardefref = new VariableDefinitionReference(vardef); @@ -90,8 +99,7 @@ namespace Xamarin.Forms.Build.Tasks Context.Variables[node] = vardef; } - XmlName propertyName; - if (TryGetPropertyName(node, parentNode, out propertyName)) + if (propertyName != XmlName.Empty || TryGetPropertyName(node, parentNode, out propertyName)) { if (skips.Contains(propertyName)) return; @@ -675,4 +683,4 @@ namespace Xamarin.Forms.Build.Tasks return vardefref.VariableDefinition; } } -} \ No newline at end of file +} diff --git a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml index 133e0e9b..da844ed0 100644 --- a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml @@ -3,6 +3,9 @@ xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests" + xmlns:d="ignoreme" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" x:Class="Xamarin.Forms.Xaml.UnitTests.SetValue"> @@ -74,5 +77,11 @@ + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs index ce377a71..2226402c 100644 --- a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs +++ b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs @@ -207,6 +207,14 @@ namespace Xamarin.Forms.Xaml.UnitTests var page = new SetValue(useCompiledXaml); Assert.That(page.stack4.Children[0], Is.TypeOf