Browse Source

bugfix : Collection Instance == 0 fixes: Animation1 Unit Test

pull/584/head
jkuehner 11 years ago
parent
commit
e53c26fb04
  1. 82
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

82
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -22,6 +22,7 @@ using System.ComponentModel;
using System.Globalization; using System.Globalization;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
@ -327,36 +328,52 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
foreach (XmlNode childNode in elementChildNodes) { if (collectionType != null && collectionInstance == null && elementChildNodes.Count() == 1)
XmlElement childElement = childNode as XmlElement; {
if (childElement != null) { var firstChild = elementChildNodes.First() as XmlElement;
if (childElement.NamespaceURI == XamlConstants.XamlNamespace) if (ObjectChildElementIsCollectionInstance(firstChild, collectionType))
continue; {
collectionInstance = ParseObject(firstChild);
if (ObjectChildElementIsPropertyElement(childElement)) { collectionProperty.PropertyValue = (XamlPropertyValue) collectionInstance;
ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty); }
continue; else
} {
} throw new XamlLoadException("Collection Instance is null");
if (initializeFromTextValueInsteadOfConstructor != null) }
continue; }
XamlPropertyValue childValue = ParseValue(childNode); else
if (childValue != null) { {
if (collectionProperty != null) { foreach (XmlNode childNode in elementChildNodes) {
collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue); XmlElement childElement = childNode as XmlElement;
CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue); if (childElement != null) {
} else { if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
if (defaultProperty == null) continue;
throw new XamlLoadException("This element does not have a default value, cannot assign to it");
if (ObjectChildElementIsPropertyElement(childElement)) {
if (isDefaultValueSet) ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty);
throw new XamlLoadException("default property may have only one value assigned"); continue;
}
obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue)); }
isDefaultValueSet = true; if (initializeFromTextValueInsteadOfConstructor != null)
} continue;
} XamlPropertyValue childValue = ParseValue(childNode);
} if (childValue != null) {
if (collectionProperty != null) {
collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue);
CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue);
} else {
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");
obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
isDefaultValueSet = true;
}
}
}
}
} }
IEnumerable<XmlNode> GetNormalizedChildNodes(XmlElement element) IEnumerable<XmlNode> GetNormalizedChildNodes(XmlElement element)
@ -582,6 +599,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
return element.LocalName.Contains("."); return element.LocalName.Contains(".");
} }
static bool ObjectChildElementIsCollectionInstance(XmlElement element, Type collectionType)
{
return element.Name == collectionType.Name;
}
static bool IsElementChildACollectionForProperty(XamlTypeFinder typeFinder, XmlElement element, XamlPropertyInfo propertyInfo) static bool IsElementChildACollectionForProperty(XamlTypeFinder typeFinder, XmlElement element, XamlPropertyInfo propertyInfo)
{ {
return element.ChildNodes.Count == 1 && propertyInfo.ReturnType.IsAssignableFrom(FindType(typeFinder, element.FirstChild.NamespaceURI, element.FirstChild.LocalName)); return element.ChildNodes.Count == 1 && propertyInfo.ReturnType.IsAssignableFrom(FindType(typeFinder, element.FirstChild.NamespaceURI, element.FirstChild.LocalName));

Loading…
Cancel
Save