测试用的序列化方法
對于實體,進行底層方法測試的時候,經常逐一賦值很麻煩,網上找到序列化xml方法,感覺挺好用的。
?
前端調用方法時,將實體序列化寫入xml文件
//xml路徑
string filePath = @"D:\1.xml";using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filePath)){//fileinfo為實體名稱
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(fileinfo.GetType());xs.Serialize(writer, fileinfo);writer.Close();}
?
測試底層方法時,通過讀取xml獲得實體
?
//xml路徑
string filePath = @"D:\1.xml";if (System.IO.File.Exists(filePath)){using (System.IO.StreamReader reader = new System.IO.StreamReader(filePath)){//fileinfo為待測試的實體名稱
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(fileinfo.GetType());object obj = xs.Deserialize(reader);reader.Close();//FileInfo_Logistic_Entity為待測試的實體類型
fileinfo = obj as FileInfo_Logistic_Entity;}}
?
轉載于:https://www.cnblogs.com/starpnd/p/3964077.html
總結
- 上一篇: bootstrap3中关于布局的两种样式
- 下一篇: 乌镇西栅免费表演项目