我有一个属性列表,所有属性都是公共的,并且有getter和setter。但并非所有这些都是序列化的,很少有人丢失。谁能告诉我可能的原因是什么?
public class student
{
public int id {get; set;};
public string fname {get; set;};
public string lname {get; set;};
}
[XmlInclude(typeof(student))]
public class event
{}
XmlSerializer xmlSerializer = new XmlSerializer(event.GetType());
FileStream fileStream = File.Open(
filePathWithName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.ReadWrite);
xmlSerializer.Serialize(fileStream, event);
var stringwriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(event.GetType());
serializer.Serialize(stringwriter, event);
<?xml version="1.0"?>
<Student>
<id>1</id>
<fname>abc</fname>
</Student>
现在这里缺少属性lname