Сериализация и десериализация в одном из методов не работает как положено - C#
Формулировка задачи:
в двух классах есть методы сериализации и десериализации, в одном все работает нормально, во втором нет, подскажите в чем проблема
public void Serialize(List<Clients> buf)
{
string path = @"data/clients.xml";
XmlSerializer writer = new XmlSerializer(typeof (List<Clients>));
try
{
Stream file;
if (File.Exists(path))
{
File.Delete(path);
file = File.Create(path);
}
else file = File.OpenWrite(path);
writer.Serialize(file, buf);
}
catch (Exception e)
{
MessageBox.Show(@"Exception - " + e.Message);
}
}
//метод считывает информацию из xml файла и возвращает ее из метода по ссылке
public void Deserialize(out List<Clients> buf)
{
string path = @"data/clients.xml";
try
{
XmlSerializer reader = new XmlSerializer(typeof(List<Clients>));
using (Stream file = File.OpenRead(path))
buf = (List<Clients>) reader.Deserialize(file);
}
catch (Exception e)
{
MessageBox.Show(@"Exception - " + e.Message);
buf = null;
}
}public void Serialize(List<List<Orders>> buf)
{
string path = @"data/orders.xml";
XmlSerializer writer = new XmlSerializer(typeof(List<List<Orders>>));
try
{
Stream file;
if (File.Exists(path))
{
File.Delete(path);
file = File.Create(path);
}
else file = File.OpenWrite(path);
writer.Serialize(file, buf);
}
catch (Exception e)
{
MessageBox.Show(@"Exception - " + e.Message);
}
}
//метод считывает информацию из xml файла и возвращает ее из метода по ссылке
public void Deserialize(out List<List<Orders>> buf)
{
string path = @"data/clients.xml";
try
{
XmlSerializer reader = new XmlSerializer(typeof(List<Orders>));
using (Stream file = File.OpenRead(path))
buf = (List<List<Orders>>)reader.Deserialize(file);
}
catch (Exception e)
{
MessageBox.Show(@"Exception - " + e.Message);
buf = null;
}
}Решение задачи: «Сериализация и десериализация в одном из методов не работает как положено»
textual
Листинг программы
<ArrayOfOrders><Orders></Orders></ArrayOfOrders>