你好我想用XMLserializer在C#中序列化一个类。编译器说Room(myClass)不是原始的(我使用Unity3d),因此无法序列化。问题是,大多数教程仅适用于具有一些简单字段的简单类。你可以帮我改变房间可序列化吗?
[Serializable]
public class Room
{
public Room()
{
m_id = "test";
m_section = Areas.PublicSec;
m_connections = null;
m_size = 10;
}
public Room(string _id, Areas _section, List<string> _connections, int _size)
{
// f.e. Bathroom
m_id = _id;
// private, public or hallway filled with the enum Areas
m_section = _section;
// list of rooms that have or will have a Connection
if (_connections != null)
{
m_connections = _connections;
}
else
{
m_connections = new List<string>();
}
//? Desired minium size of the room
m_size = _size;
}
private string m_id;
public string id
{
get { return m_id; }
set { m_id = value;}
}
private Areas m_section;
public Areas Section
{
get { return m_section; }
set { m_section = value; }
}
private List<string> m_connections;
[XmlArray("m_connections")]
public List<string> Connections
{
get { return m_connections; }
set { m_connections = value; }
}
private int m_size;
public int Size
{
get { return m_size; }
set { m_size = value; }
}
}
我的XMLSerializer适用于简单的类,但不适用于此类。