如何通过使用 Visual C#中序列化到 XML 对象
1个回答
展开全部
序列化
XmlSerializer xml = new XmlSerializer(typeof(实体类));
StreamWriter sw = new StreamWriter(@"相对路径", false);
xml.Serialize(sw, 实体类的对象);
sw.Flush();
sw.Close();
反序列化
XmlSerializer formatter = new XmlSerializer(typeof(实体));
StreamReader sr = new StreamReader(@"相对路径");
UserForLoginModel ufl = (实体类)formatter.Deserialize(sr);
sr.Close();
XmlSerializer xml = new XmlSerializer(typeof(实体类));
StreamWriter sw = new StreamWriter(@"相对路径", false);
xml.Serialize(sw, 实体类的对象);
sw.Flush();
sw.Close();
反序列化
XmlSerializer formatter = new XmlSerializer(typeof(实体));
StreamReader sr = new StreamReader(@"相对路径");
UserForLoginModel ufl = (实体类)formatter.Deserialize(sr);
sr.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询