私の問題は単純です。このファイルを逆シリアル化すると、すべての値が 0 に設定されます。一部のコードはより明示的になります。
メインクラス:
public partial class MainPage : PhoneApplicationPage
{
Elements file = null;
// Constructor
public MainPage()
{
InitializeComponent();
load_map("clxml.xml");
}
public void load_map(string path)
{
// deserialize xmlfile_config_map
XmlSerializer serializer = new XmlSerializer(typeof(Elements));
StreamReader reader = new StreamReader(path);
try
{
file = (Elements)serializer.Deserialize(reader);
}catch(Exception e){
}
MessageBox.Show((file.listObjet[1].id).ToString());
MessageBox.Show((file.listObjet[2].pos_x).ToString());
reader.Close();
}
}
私が埋めるクラス:
//[Serializable]
public class Element
{
[System.Xml.Serialization.XmlElement("id")]
public int id { get; set; }
[System.Xml.Serialization.XmlElement("pos_x")]
public int pos_x { get; set; }
[System.Xml.Serialization.XmlElement("pos_y")]
public int pos_y { get; set; }
[System.Xml.Serialization.XmlElement("rot")]
public int rot { get; set; }
}
//[Serializable()]
[System.Xml.Serialization.XmlRoot("droot")]
public class Elements
{
[XmlElement("Element")]
public List<Element> listObjet { get; set; }
およびxmlファイル:
<Element id="4" pos_x="85" pos_y="43" rot="34"/>
これはこのような行ですが、問題はここにあるとは思いません。