I m having troubles with XamlServices Serialization/Deserialisation. I have this class :
[RuntimeNameProperty("Name")]
[ContentProperty("Children")]
public class Node
{
public Node()
{
}
public string Name { get; set; }
public int Valeur { get; set; }
public Node Parent
{
get;
set;
}
public bool HasChildren
{
get { return mChildren.Count > 0; }
}
public NodeList Children
{
get { return mChildren; }
set { mChildren = value; }
}
NodeList mChildren = new NodeList();
}
语言学家是一个短类,其定义是:
public class NodeList : IList<Node>
{
// ... implemented using a List<Node> internally
}
If I create a node hierarchy, like this :
Node root = new Node() { Name = "A", Valeur = 2, Parent = null };
root.Children.Add( new Node() { Name = "A1", Valeur = 3, Parent = root } );
root.Children.Add( new Node() { Name = "A2", Valeur = 3, Parent = root } );
root.Children[0].Children.Add( new Node() { Name = "A21", Valeur = 5, Parent = root.Children[0] } );
并且我以这种方式编篡:
using( TextWriter writer = File.CreateText( "test.xaml" ) )
{
XamlServices.Save( writer, root );
}
由此而产生的xaml :
<Node Parent="{x:Null}" x:Name="__ReferenceID1" Name="A" Valeur="2"
xmlns="clr-namespace:TestCRTP;assembly=TestCRTP"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Node Parent="{x:Reference A}" x:Name="__ReferenceID0" Name="A1" Valeur="3">
<Node Parent="{x:Reference A1}" Name="A21" Valeur="5">
<NodeList />
</Node>
</Node>
<Node Parent="{x:Reference A}" Name="A2" Valeur="3">
<NodeList />
</Node>
</Node>
如你所知,Xaml Services公司正在产生“_ReferenceID0”特性,因为有RuntimeNameProperty称号。 显然,它之所以这样做,是因为X:Reference(由于父母关系),但最棘手的是,它甚至不使用产生的x:Name! 当然,当我试图将其erial弄时,它就变得最糟:
using( TextReader reader = File.OpenText( "test.xaml" ) )
{
Node node = XamlServices.Load( reader ) as Node;
}
我提到“姓名财产已经定在诺德”,这是合乎逻辑的,因为确实已经有一个名字......。
任何cl?