Jump to content
  • Advertisement
Sign in to follow this  
akira32

XmlSerializer does not support the case of List within List

This topic is 2604 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I put my XmlSerializer code as below:
The code in windows and winform project are all right. But with the same code in windows phone 7 project, it will lose the two-dims array (my CellArray). Should I convert two-dims list array to one-dim list array in windows phone 7 project? Does someone have any idea for the case of List within List in XmlSerializer?

<?xml version="1.0"?>
<SaveFightFloorData xmlns:xsi="http://www.w3.org/20...Schema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<hexWidth>1</hexWidth>
<size>
<X>10</X>
<Y>10</Y>
</size>
<CellArray>
<ArrayOfCellData>
<CellData>
<cellType>START</cellType>
<thingType>ROCK0</thingType>
<objectType>NONE</objectType>
<dist>0</dist>
</CellData>
<CellData>
<cellType>NONE</cellType>
<thingType>ROCK0</thingType>
<objectType>NONE</objectType>
<dist>0</dist>
</CellData>



//[Serializable]
public class SaveFightFloorData
{
public float hexWidth;
public Point size;

//public List<CellData> CellArrayOne=new List<CellData>();
public List<List<CellData>> CellArray = null;

//public List<bool> MovableCellArrayOne = new List<bool>();
public List<List<bool>> MovableCellArray = null;

//moveable cell array unfinished

public Point StartLocation;
public Point EndLocation;


public static SaveFightFloorData LoadFightFloorFile(string filename)
{
FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);

// Read the data from the file.
XmlSerializer serializer = new XmlSerializer(typeof(SaveFightFloorData));
SaveFightFloorData SaveFightFloorData = (SaveFightFloorData)serializer.Deserialize(stream);

// Close the file.
stream.Close();

return SaveFightFloorData;
}

Share this post


Link to post
Share on other sites
Advertisement
I had HEAPS of trouble doing pretty much the same. I tried list of lists, array of lists, list of arrays etc.

Eventually i settled for the intermediate serializer which did a great job on serializing my fairly complicated data into XML.However the intermediate serializer is not compatible with xbox (don't know about the win phone).


XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;

using (XmlWriter writer = XmlWriter.Create("test.xml", settings))
{
IntermediateSerializer.Serialize(writer, mapData, null);
}


You might want to go to this blog http://www.talula.de.../blogindex.html and scroll down to the inermediate serializer section.

You should add a helper library to manage your data somehow, heres how my helper classes look for my tile engine:

MapDataHelper.cs

public struct MapData
{
public string MapName; //to store and load the correct map name
public int TileWidth; //The size to draw the tiles
public int TileHeight; //The height to draw the tiles
public int MapWidth; //Used in foreach loop to draw the row length
public int MapHeight; //Used in foreach loop to draw collumn lenght

public List<BaseMapTile>[] MapTiles; // Here is that array of lists.
}

public MapData mapData;


BaseMapTile.cs
[assembly: SecurityTransparent]
namespace HelperLibrary
{
public class BaseMapTile
{
public Vector2 Position { get; set; }
}
}


groundTile.cs
public class GroundTile : BaseMapTile
{

public Texture2D GroundTexture { get; set; }
public bool Passable { get; set; }
public int TimeUnitCost { get; set; }
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!