[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Generic Dictionary Serialized with Xaml

bcfj74

3/4/2008 4:45:00 PM

I'm having some troubles with Xaml as a serialization option. The
problem lies in serializing nested Generic dictionaries: Basically, I
see different XML if the first element of the dictionary's values is a
primitive versus if it is another dictionary. If the first element is
a primitive, I get an extra layer of XML tags (I say extra, but, they
do seem to be neccessary). If the first element is not a primitive,
those tags are missing and the XamlReader cannot read the output Xaml
back in..

Here's a simple test case:

namespace WpfApplication1
{
public class MyDictionary :
System.Collections.Generic.Dictionary<string, object>
{
}

public class UseMyDictionary
{
public UseMyDictionary()
{
MyDictionary = new MyDictionary();
}
private MyDictionary _myDictionary;


[System.ComponentModel.DefaultValueAttribute(null)]
public MyDictionary MyDictionary
{
get { return _myDictionary; }
set { _myDictionary = value; }
}

public static void STRANGE_CASE()
{
UseMyDictionary use = new UseMyDictionary();
use.MyDictionary["b"] = true;

Console.Out.WriteLine(System.Windows.Markup.XamlWriter.Save(use));
/*
<UseMyDictionary xmlns="clr-
namespace:WpfApplication1;assembly=WpfApplication1" xmlns:s="clr-
namespace:System;assembly=mscorlib" xmlns:assembly="http://
schemas.microsoft.com/winfx/2006/xaml">
<UseMyDictionary.MyDictionary>
<MyDictionary>
<s:Boolean assembly:Key="b">True</s:Boolean>
</MyDictionary>
</UseMyDictionary.MyDictionary>
</UseMyDictionary>
*/
use.MyDictionary["c"] = new MyDictionary();

Console.Out.WriteLine(System.Windows.Markup.XamlWriter.Save(use));
/*
<UseMyDictionary xmlns="clr-
namespace:WpfApplication1;assembly=WpfApplication1" xmlns:s="clr-
namespace:System;assembly=mscorlib" xmlns:assembly="http://
schemas.microsoft.com/winfx/2006/xaml">
<UseMyDictionary.MyDictionary>
<MyDictionary>
<s:Boolean assembly:Key="b">True</s:Boolean>
<MyDictionary assembly:Key="c" />
</MyDictionary>
</UseMyDictionary.MyDictionary>
</UseMyDictionary>
*/
use.MyDictionary["a"] = new MyDictionary();

Console.Out.WriteLine(System.Windows.Markup.XamlWriter.Save(use));
/*
<UseMyDictionary xmlns="clr-
namespace:WpfApplication1;assembly=WpfApplication1"
xmlns:assembly="http://schemas.microsoft.com/winfx/2006/...
xmlns:s="clr-namespace:System;assembly=mscorlib">
<UseMyDictionary.MyDictionary>
<MyDictionary assembly:Key="a" />
<s:Boolean assembly:Key="b">True</s:Boolean>
<MyDictionary assembly:Key="c" />
</UseMyDictionary.MyDictionary>
</UseMyDictionary>
*/
}
}
}