I want to serialize an object that contains properties and one of these properties I want only to serialize its name.
How to do this without implmeneting IXmlSerializable interface, only using attributes.
[Serializable]
public class Class
{
public Class()
{
}
[XmlAttribute]
public string ClassId{get;set;}
[XmlAttribute]
public Teacher Teacher{get;set;}
[XmlArray("Students")]
[XmlArrayItem("Student", Type=typeof(Student))]
public List<Student> Students { get; } = new List<Student>();
}
[Serializable]
public class Student
{
public Student()
{
}
public Class CurrentClass{get;set;}
[XmlAttribute]
public string Name { get; set; } = "New Student";
[XmlAttribute]
public int Age { get; set; } = 10;
}
CurrentClass this property I don't want to ignore it.
I want to serialize only its CurrentClass.ClassId value.
If you are looking just for the ClassId to be serialized with the Student object it makes more sense to just have a ClassId property rather than the entire Class object.