IntermediateSerializer XNA 4.如何反序列化列表列表或词典列表?

时间:2014-02-12 13:16:50

标签: c# xna

如何反序列化列表列表或词典列表? 这是C#代码:

public enum Values : byte
{
    One,
    Two,
    Three,
    Four
}
public class Something
{
    public int Some_int { get; set; }
}
public class Test
{
    public List<List<Something>> ListOfSomethingLists { get; set; }
    public List<Dictionary<Values, Something>> ListOfSomethingDictionaries { get; set; }
}

这是XML不起作用因为我不知道如何反序列化它:

    <?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <Asset Type="Test">
    <ListOfSomethingLists>
      <Item>
        <Item>
           1
        </Item>
        <Item>
           2
        </Item>
      </Item>
      <Item>
        <Item>
           3
        </Item>
        <Item>
           4
        </Item>
      </Item>
    </ListOfSomethingLists>
    <ListOfSomethingDictionaries>
      <Item>
        <Item>
          <Key>One</Key>
          <Value>1</Value>
        </Item>
        <Item>
          <Key>Two</Key>
          <Value>2</Value>
        </Item>
      </Item>
      <Item>
        <Item>
          <Key>Three</Key>
          <Value>3</Value>
        </Item>
        <Item>
          <Key>Four</Key>
          <Value>4</Value>
        </Item>
      </Item>
    </ListOfSomethingDictionaries>
  </Asset>
</XnaContent>

我实际上没有测试这段代码,但我在游戏中几乎一样。并且仍然混淆了如何反序列化列表列表和字典列表。提前谢谢。

1 个答案:

答案 0 :(得分:1)

通过这种解释,您应该可以解决您的问题。

http://xboxforums.create.msdn.com/forums/p/70599/614469.aspx

小例子。

    [assembly: SecurityTransparent] 
    namespace randomnamespace
    { 
        public class randomclass
        { 

        } 
    }