[X] Allow empty property xaml-elements (#5550)
authorStephane Delcroix <stephane@delcroix.org>
Mon, 18 Mar 2019 21:58:36 +0000 (22:58 +0100)
committerSamantha Houts <samhouts@users.noreply.github.com>
Mon, 18 Mar 2019 21:58:36 +0000 (14:58 -0700)
- fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/817710?src=WorkItemMention&src-action=artifact_link
- reverts #4582

Xamarin.Forms.Xaml.UnitTests/Issues/DO817710.xaml [new file with mode: 0644]
Xamarin.Forms.Xaml.UnitTests/Issues/DO817710.xaml.cs [new file with mode: 0644]
Xamarin.Forms.Xaml.UnitTests/Issues/Gh4553.xaml [deleted file]
Xamarin.Forms.Xaml.UnitTests/Issues/Gh4553.xaml.cs [deleted file]
Xamarin.Forms.Xaml/XamlParser.cs

diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/DO817710.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/DO817710.xaml
new file mode 100644 (file)
index 0000000..e9a6943
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.DO817710">
+    <ContentPage.Resources />
+</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/DO817710.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/DO817710.xaml.cs
new file mode 100644 (file)
index 0000000..9bd0895
--- /dev/null
@@ -0,0 +1,30 @@
+using System;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+using Xamarin.Forms;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+       public partial class DO817710 : ContentPage
+       {
+               public DO817710() => InitializeComponent();
+               public DO817710(bool useCompiledXaml)
+               {
+                       //this stub will be replaced at compile time
+               }
+
+               [TestFixture]
+               class Tests
+               {
+                       [SetUp] public void Setup() => Device.PlatformServices = new MockPlatformServices();
+                       [TearDown] public void TearDown() => Device.PlatformServices = null;
+
+                       [Test]
+                       public void EmptyResourcesElement([Values(false, true)]bool useCompiledXaml)
+                       {
+                               Assert.DoesNotThrow(() => new DO817710(useCompiledXaml: useCompiledXaml));
+                       }
+               }
+       }
+}
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4553.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4553.xaml
deleted file mode 100644 (file)
index 5824c43..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ContentPage
-               xmlns="http://xamarin.com/schemas/2014/forms"
-               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
-               x:Class="Xamarin.Forms.Xaml.UnitTests.Gh4553">
-       <Grid IsVisible="{Binding}">
-               <Grid.ColumnDefinitions/>
-       </Grid>
-</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4553.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh4553.xaml.cs
deleted file mode 100644 (file)
index 7937cac..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-using System;
-using System.Collections.Generic;
-using NUnit.Framework;
-using Xamarin.Forms;
-using Xamarin.Forms.Core.UnitTests;
-
-namespace Xamarin.Forms.Xaml.UnitTests
-{
-       [XamlCompilation(XamlCompilationOptions.Skip)]
-       public partial class Gh4553 : ContentPage
-       {
-               public Gh4553()
-               {
-                       InitializeComponent();
-               }
-               public Gh4553(bool useCompiledXaml)
-               {
-                       //this stub will be replaced at compile time
-               }
-
-               [TestFixture]
-               class Tests
-               {
-                       [SetUp] public void Setup() => Device.PlatformServices = new MockPlatformServices();
-                       [TearDown] public void TearDown() => Device.PlatformServices = null;
-
-                       [TestCase(true), TestCase(false)]
-                       public void ThrowMeaningfulError(bool useCompiledXaml)
-                       {
-                               if (useCompiledXaml)
-                                       Assert.Throws<XamlParseException>(() => MockCompiler.Compile(typeof(Gh4553)));
-                               else
-                                       Assert.Throws<XamlParseException>(() => new Gh4553(useCompiledXaml));
-                       }
-               }
-       }
-}
index afa3971..6da68c1 100644 (file)
@@ -80,9 +80,11 @@ namespace Xamarin.Forms.Xaml
                                                        else //Attached BP
                                                                name = new XmlName(reader.NamespaceURI, reader.LocalName);
 
+                                                       INode prop = null;
                                                        if (reader.IsEmptyElement)
-                                                               throw new XamlParseException($"Unexpected empty element '<{reader.Name}/>'", (IXmlLineInfo)reader);
-                                                       var prop = ReadNode(reader);
+                                                               Debug.WriteLine($"Unexpected empty element '<{reader.Name} />'", (IXmlLineInfo)reader);
+                                                       else
+                                                               prop = ReadNode(reader);
                                                        if (prop != null)
                                                                node.Properties.Add(name, prop);
                                                }
@@ -156,10 +158,7 @@ namespace Xamarin.Forms.Xaml
 
                                                IList<XmlType> typeArguments = null;
                                                if (attributes.Any(kvp => kvp.Key == XmlName.xTypeArguments))
-                                               {
-                                                       typeArguments =
-                                                               ((ValueNode)attributes.First(kvp => kvp.Key == XmlName.xTypeArguments).Value).Value as IList<XmlType>;
-                                               }
+                                                       typeArguments = ((ValueNode)attributes.First(kvp => kvp.Key == XmlName.xTypeArguments).Value).Value as IList<XmlType>;
 
                                                node = new ElementNode(new XmlType(elementNsUri, elementName, typeArguments), elementNsUri,
                                                        reader as IXmlNamespaceResolver, elementXmlInfo.LineNumber, elementXmlInfo.LinePosition);