Browse Source

IDictionary (and not just ResourceDictionary) is considered a collection and supported by own XamlParser.

pull/77/head
gumme 12 years ago
parent
commit
91ef4ab5c9
  1. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleClassContainer.cs
  2. 82
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs
  3. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

17
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleClassContainer.cs

@ -11,6 +11,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -11,6 +11,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
}
public class ExampleClassDictionary : Dictionary<string, ExampleClass>
{
}
[ContentProperty("List")]
public class ExampleClassContainer : ExampleClass
{
@ -35,5 +39,18 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -35,5 +39,18 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
otherList = value;
}
}
ExampleClassDictionary dictionary = new ExampleClassDictionary();
public ExampleClassDictionary Dictionary {
get {
TestHelperLog.Log("Dictionary.get " + Identity);
return dictionary;
}
set {
TestHelperLog.Log("Dictionary.set " + Identity);
dictionary = value;
}
}
}
}

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

@ -208,6 +208,88 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -208,6 +208,88 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
");
}
[Test]
public void ContainerImplicitDictionary()
{
TestLoading(@"
<ExampleClassContainer
xmlns=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<ExampleClassContainer.Dictionary>
<ExampleClass x:Key=""key1"" OtherProp=""a""> </ExampleClass>
<ExampleClass x:Key=""key2"" OtherProp=""b"" />
<ExampleClass x:Key=""key3"" OtherProp=""c"" />
</ExampleClassContainer.Dictionary>
</ExampleClassContainer>
");
}
[Test]
public void ContainerExplicitDictionary()
{
TestLoading(@"
<ExampleClassContainer
xmlns=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<ExampleClassContainer.Dictionary>
<ExampleClassDictionary>
<ExampleClass x:Key=""key1"" OtherProp=""a""> </ExampleClass>
<ExampleClass x:Key=""key2"" OtherProp=""b"" />
<ExampleClass x:Key=""key3"" OtherProp=""c"" />
</ExampleClassDictionary>
</ExampleClassContainer.Dictionary>
</ExampleClassContainer>
");
}
[Test]
public void ResourceDictionaryImplicit()
{
TestLoading(@"
<Window
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Window.Resources>
<t:ExampleClass x:Key=""key1"" OtherProp=""a""> </t:ExampleClass>
<t:ExampleClass x:Key=""key2"" OtherProp=""b"" />
</Window.Resources>
</Window>
");
}
[Test]
public void ResourceDictionaryExplicitWinfx2006()
{
ResourceDictionaryExplicitInternal("http://schemas.microsoft.com/winfx/2006/xaml/presentation");
}
[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.
// In this test case the default xmlns is set to netfx/20007 (compare with the test above that uses winfx/2006 and is successfully executed).
ResourceDictionaryExplicitInternal("http://schemas.microsoft.com/netfx/2007/xaml/presentation");
}
void ResourceDictionaryExplicitInternal(string defaultXmlns)
{
TestLoading(@"
<Window
xmlns=""" + defaultXmlns + @"""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Window.Resources>
<ResourceDictionary>
<t:ExampleClass x:Key=""key1"" OtherProp=""a""> </t:ExampleClass>
<t:ExampleClass x:Key=""key2"" OtherProp=""b"" />
</ResourceDictionary>
</Window.Resources>
</Window>
");
}
[Test]
public void ExampleServiceTest()
{

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -25,7 +25,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
return typeof(IList).IsAssignableFrom(type)
|| type.IsArray
|| typeof(IAddChild).IsAssignableFrom(type)
|| typeof(ResourceDictionary).IsAssignableFrom(type);
|| typeof(IDictionary).IsAssignableFrom(type);
}
/// <summary>
@ -65,7 +65,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -65,7 +65,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else {
addChild.AddChild(newElement.GetValueFor(null));
}
} else if (collectionInstance is ResourceDictionary) {
} else if (collectionInstance is IDictionary) {
object val = newElement.GetValueFor(null);
object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
//if (key == null || key == "") {
@ -74,7 +74,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -74,7 +74,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
//}
if (key == null || key == "")
key = val;
((ResourceDictionary)collectionInstance).Add(key, val);
((IDictionary)collectionInstance).Add(key, val);
} else {
collectionType.InvokeMember(
"Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,

Loading…
Cancel
Save