我尝试序列化 PropertyGrid 并将结果写入 XML 文件。最后,XML 文件几乎是空的;
XML 文件
<?xml version="1.0" encoding="utf-8"?>
<MyBookCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
我的代码;
private void btnSave_Click(object sender, EventArgs e)
{
MyBookCollection MyBooks = new MyBookCollection ();
SerializeToXML(MyBooks);
}
public void SerializeToXML(MyBookCollection MyBooks)
{
XmlSerializer serializer = new XmlSerializer(typeof(MyBookCollection ));
TextWriter textWriter = new StreamWriter(@"D:\BookInfo.xml");
serializer.Serialize(textWriter, MyBooks);
textWriter.Close();
}
}
[Serializable]
public class MyBookCollection
{
string m_Title;
[Category("Book Titles")]
[ReadOnly(true)]
public string Title
{
get { return m_Title; }
set { m_Caption = Title; }
}
}
出了什么问题或如何做得更好
语言:C#