带有get和set的公共属性未由XMLSERIALIZER序列化

时间:2014-02-27 12:23:04

标签: c# xmlserializer

我有一个属性列表,所有属性都是公共的,并且有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
{}

// Xml Serializer

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文件

<?xml version="1.0"?>
<Student>
<id>1</id>
<fname>abc</fname>
</Student>  

现在这里缺少属性lname

0 个答案:

没有答案