I have a class that I want to serialise to XML:
public class Infinitive
{
private string english;
private string spanish;
private string[] englishAccepted;
private ConjugationModel model;
public Infinitive()
{
//Parameterless constructor to allow the class to be serialised
}
public Infinitive(string english, string spanish) //Constructor if only 1 acceptable answer for English and regular conjugation
{
this.english = english;
this.spanish = spanish;
englishAccepted = new string[] { english };
model = (ConjugationModel)RegularConjugation(spanish);
}
public Infinitive(string english, string spanish, string[] englishAccepted) //Constructor if multiple answers for English
{
this.english = english;
this.spanish = spanish;
if (englishAccepted[0] == "") //Handling for if englishAccepted is blank
{
this.englishAccepted = new string[] { english };
}
else
{
this.englishAccepted = englishAccepted;
}
model = (ConjugationModel)RegularConjugation(spanish);
}
public string English { get => english; }
public string Spanish { get => spanish; }
public ConjugationModel Model { get => model; }
public string[] EnglishAccpeted { get => englishAccepted; }
//There are also some methods in the class
And a fairly straightforward serialiser
public void Serialise<T>(T[] objects, string filename)
{
XmlSerializer serializer = new XmlSerializer(typeof(T[]));
TextWriter writer = new StreamWriter(filename);
serializer.Serialize(writer, objects);
writer.Close();
}
However, when I input data and run the program, the file gets created and I end up with the following XML:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfInfinitive xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Infinitive />
<Infinitive />
<Infinitive />
<Infinitive />
<Infinitive />
<Infinitive />
<Infinitive />
<Infinitive />
</ArrayOfInfinitive>
I have experimented with using XML serialisation tags, such as [Serializable]
and [XmlElement]
but nothing has changed the output so far.
What am I doing wrong?
Thanks in advance