Browse Source

Fix multiple XML-Namspaces for the same CLR-Namespace

Now all UnitTests work
pull/604/head
jogibear9988 11 years ago
parent
commit
19486b6cf2
  1. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs
  2. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
  3. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  4. 27
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs

@ -293,7 +293,6 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -293,7 +293,6 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
}
[Test]
[Ignore("Own XamlParser should handle different namespaces pointing to same types, because builtin XamlReader does.")]
public void ResourceDictionaryExplicitNetfx2007()
{
// The reason this test case fails is because own XamlParser cannot always handle the case where multiple xmlns points to the same type.

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

@ -228,6 +228,16 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -228,6 +228,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
return _typeFinder.GetXmlNamespaceFor(type.Assembly, type.Namespace, getClrNamespace);
}
internal List<string> GetNamespacesFor(Type type, bool getClrNamespace = false)
{
if (type == typeof (DesignTimeProperties))
return new List<string>(){XamlConstants.DesignTimeNamespace};
if (type == typeof (MarkupCompatibilityProperties))
return new List<string>(){XamlConstants.MarkupCompatibilityNamespace};
return _typeFinder.GetXmlNamespacesFor(type.Assembly, type.Namespace, getClrNamespace);
}
internal string GetPrefixForNamespace(string @namespace)
{

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -356,19 +356,19 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -356,19 +356,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
static XmlNode FindChildNode(XmlNode node, Type elementType, string propertyName, XamlDocument xamlDocument)
{
var localName = elementType.Name + "." + propertyName;
var namespaceURI = xamlDocument.GetNamespaceFor(elementType);
var namespacesURI = xamlDocument.GetNamespacesFor(elementType);
var clrNamespaceURI = xamlDocument.GetNamespaceFor(elementType, true);
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == localName && (childNode.NamespaceURI == namespaceURI || childNode.NamespaceURI == clrNamespaceURI))
if (childNode.LocalName == localName && (namespacesURI.Contains(childNode.NamespaceURI) || childNode.NamespaceURI == clrNamespaceURI))
{
return childNode;
}
}
var type = elementType.BaseType;
namespaceURI = xamlDocument.GetNamespaceFor(type);
namespacesURI = xamlDocument.GetNamespacesFor(type);
while (type != typeof(object))
{
@ -379,7 +379,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -379,7 +379,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI)
if (childNode.LocalName == localName && namespacesURI.Contains(childNode.NamespaceURI))
{
return childNode;
}

27
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows.Markup;
using System.Xaml;
@ -82,6 +83,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -82,6 +83,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
Dictionary<string, XamlNamespace> namespaces = new Dictionary<string, XamlNamespace>();
Dictionary<AssemblyNamespaceMapping, string> reverseDict = new Dictionary<AssemblyNamespaceMapping, string>();
Dictionary<AssemblyNamespaceMapping, List<string>> reverseDictList = new Dictionary<AssemblyNamespaceMapping, List<string>>();
/// <summary>
/// Gets a type referenced in XAML.
@ -128,6 +130,20 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -128,6 +130,20 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
/// <summary>
/// Gets the XML namespaces that can be used for the specified assembly/namespace combination.
/// </summary>
public List<string> GetXmlNamespacesFor(Assembly assembly, string @namespace, bool getClrNamespace = false)
{
AssemblyNamespaceMapping mapping = new AssemblyNamespaceMapping(assembly, @namespace);
List<string> xmlNamespaces;
if (!getClrNamespace && reverseDictList.TryGetValue(mapping, out xmlNamespaces)) {
return xmlNamespaces;
} else {
return new List<string>() { "clr-namespace:" + mapping.Namespace + ";assembly=" + mapping.Assembly.GetName().Name };
}
}
/// <summary>
/// Gets the prefix to use for the specified XML namespace,
/// or null if no suitable prefix could be found.
@ -178,6 +194,14 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -178,6 +194,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
ns.ClrNamespaces.Add(mapping);
List<string> xmlNamespaceList;
if (reverseDictList.TryGetValue(mapping, out xmlNamespaceList)) {
if (!xmlNamespaceList.Contains(ns.XmlNamespace))
xmlNamespaceList.Add(ns.XmlNamespace);
}
else
reverseDictList.Add(mapping, new List<string>(){ ns.XmlNamespace });
string xmlNamespace;
if (reverseDict.TryGetValue(mapping, out xmlNamespace)) {
if (xmlNamespace == XamlConstants.PresentationNamespace) {
@ -262,6 +286,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -262,6 +286,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
foreach (KeyValuePair<AssemblyNamespaceMapping, string> pair in source.reverseDict) {
this.reverseDict.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<AssemblyNamespaceMapping, List<string>> pair in source.reverseDictList) {
this.reverseDictList.Add(pair.Key, pair.Value.ToList());
}
}
object ICloneable.Clone()

Loading…
Cancel
Save