From e5761c6d5c53d93c179570314251a77c1088a07b Mon Sep 17 00:00:00 2001 From: Tobias Gummesson Date: Mon, 8 Jul 2013 01:59:49 -0700 Subject: [PATCH] Removed Ignore attribute from SimpleLoadTests so the tests in the class will be executed. Made some modifications to XamlParser so it aligns with the official XamlReader and the SimpleLoadTests will pass. --- .../Tests/XamlDom/SimpleLoadTests.cs | 1 - .../WpfDesign.XamlDom/Project/XamlParser.cs | 28 ++++++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs index 0928cc50fd..f21923390f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs @@ -7,7 +7,6 @@ using NUnit.Framework; namespace ICSharpCode.WpfDesign.Tests.XamlDom { [TestFixture] - [Ignore("Broken on .NET 4")] public class SimpleLoadTests : TestHelper { [Test] diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs index 0d9abcf9cb..3c1288e2a0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs @@ -265,7 +265,7 @@ namespace ICSharpCode.WpfDesign.XamlDom void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor) { - XamlPropertyValue setDefaultValueTo = null; + bool isDefaultValueSet = false; object defaultPropertyValue = null; XamlProperty defaultCollectionProperty = null; @@ -290,11 +290,6 @@ namespace ICSharpCode.WpfDesign.XamlDom continue; if (ObjectChildElementIsPropertyElement(childElement)) { - // I don't know why the official XamlReader runs the property getter - // here, but let's try to imitate it as good as possible - if (defaultProperty != null && !defaultProperty.IsCollection) { - defaultProperty.GetValue(obj.Instance); - } ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue); continue; } @@ -307,24 +302,17 @@ namespace ICSharpCode.WpfDesign.XamlDom defaultCollectionProperty.ParserAddCollectionElement(null, childValue); CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue); } else { - if (setDefaultValueTo != null) + if (defaultProperty == null) + throw new XamlLoadException("This element does not have a default value, cannot assign to it"); + + if (isDefaultValueSet) throw new XamlLoadException("default property may have only one value assigned"); - setDefaultValueTo = childValue; + + obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue)); + isDefaultValueSet = true; } } } - - if (defaultProperty != null && !defaultProperty.IsCollection && !element.IsEmpty) { - // Runs even when defaultValueSet==false! - // Again, no idea why the official XamlReader does this. - defaultProperty.GetValue(obj.Instance); - } - if (setDefaultValueTo != null) { - if (defaultProperty == null) { - throw new XamlLoadException("This element does not have a default value, cannot assign to it"); - } - obj.AddProperty(new XamlProperty(obj, defaultProperty, setDefaultValueTo)); - } } int combinedNormalizedChildNodes;