我有序列化List<Server> servers
。
服务器类具有以下变量:
public class Server
{
string serverName { get; set; }
string dnsIP { get; set; }
Game game { get; set; }
和游戏类:
public class Game
{
public enum Genre { FPS, RTS, RPG, MMO, MOBA, TPS, Sandbox, Other };
private string gameName { get; set; }
private Genre genre { get; set; }
当我尝试像这样序列化时:
private void saveServersToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "XML files (*.xml)|*.xml";
saveFileDialog.InitialDirectory = ".";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
Stream myStream = null;
if ((myStream = saveFileDialog.OpenFile()) != null)
{
var serializer = new XmlSerializer(typeof(List<Server>));
serializer.Serialize(myStream, Arrays.servers);
myStream.Close();
}
saveFileDialog.Dispose();
}
}
我得到了这样的 XML 文件:
<?xml version="1.0"?>
<ArrayOfServer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Server />
<Server />
</ArrayOfServer>
我如何获取 serverName 、 dnsIP 、 gameName 、流派等所有信息。