Сериализация собственного списка - C#
Формулировка задачи:
у меня есть односвязный список
Список у меня удачно сериализует в файл числа и строки.
Но как свой клас ему подсунул он мне ексепшен выбил
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
Additional information: There was an error generating the XML document.
Ниже сам класс
Приметка (сериализовал его через List все норм было без ошибок.
Подскажите, может я не правильно как то его сериализую или что?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.Collections;
namespace l3._3._5csharp
{
[Serializable]
public class GList<T> : IEnumerable
{
private class Node
{
public T data;
public Node next;
public Node(T data, Node next)
{
this.data = data;
this.next = next;
}
}
T[] indexx;
private Node head = null;
private Node tail = null;
private int size = 0;
public void Add(T data)
{
if (head == null)
{
head = new Node(data, null);
tail = head;
}
else
{
tail = head;
while (tail.next != null)
tail = tail.next;
tail.next = new Node(data, null);
tail = tail.next;
}
size++;
}
public IEnumerator GetEnumerator()
{
for (Node r = head; r != null; r = r.next)
yield return r.data;
}
//прочие методы по такому же принципу
public static void serilaze(GList<T> vector)
{
XmlSerializer writer = new XmlSerializer(vector.GetType());
var path = @"D:\bBDstudents2.xml";
System.IO.FileStream file = System.IO.File.OpenWrite(path);
writer.Serialize(file, vector);
file.Close();
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.IO;
namespace l3._3._5csharp
{
[Serializable]
public class curnik
{
public string background;
public string color;
public long a;
public long b;
public curnik(string background, string color, long a, long b)
{
this.background = background;
this.color = color;
this.a = a;
this.b = b;
}
public curnik() { }
public long plosha()
{
return (long)a * b;
}
public long perimetr()
{
return (long)2 * (a + b);
}
public void view()
{
Console.WriteLine("a={0} b={1} perimeter={2} plosha={3} background={4} color={5}", a, b, perimetr(), plosha(), background, color);
}
}
}Решение задачи: «Сериализация собственного списка»
textual
Листинг программы
public void Add(Object data)
{
if (!(data is T)) return;
if (_head == null)
{
_head = new Node((T)data, null);
_tail = _head;
}
else
{
_tail = _head;
while (_tail.Next != null) _tail = _tail.Next;
_tail.Next = new Node((T)data, null);
_tail = _tail.Next;
}
}