2011-07-17 30 views
0

我想在XNA 4.0,其中每個節點具有通過INT索引作爲這樣的一個成員字典中的子節點序列化樹:序列化詞典4.0

[Serializable] 
public class Node 
{ 
    private Dictionary<int, Node> children; 
} 

我的本意是,當我序列化具有該節點作爲根的所有子樹都被序列化。 但是當我嘗試測試它,它似乎已經序列化的詞典中的問題,回答與錯誤(簡體):

System.InvalidOperationException was unhandled 
    Message=There was an error reflecting type 'Baddies.Node.Node'. 
    InnerException: System.NotSupportedException 
     Message=Cannot serialize member Baddies.Nodes.Node.Children of type System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Baddies.Nodes.Node, Baddies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], because it implements IDictionary. 

我的問題是雙重的。首先,如果類字典是可序列化的,那麼這會做我期望它做的事情嗎? (即,序列化所有的子樹)。其次,我該如何去序列化字典類呢?

歡迎任何及所有信息。感謝您的時間。

回答