郑雪儿三级,快乐大本营091017,丰职
#region 序列化 /// <summary> /// xml序列化 /// </summary> /// <param name="obj">序列对象</param> /// <param name="filepath">xml文件路径</param> /// <returns>是否成功</returns> public static bool serializetoxml(object obj, string filepath) { bool result = false; filestream fs = null; try { fs = new filestream(filepath, filemode.create, fileaccess.write, fileshare.readwrite); xmlserializer serializer = new xmlserializer(obj.gettype()); serializer.serialize(fs, obj); result = true; } catch (exception ex) { throw ex; } finally { if (fs != null) fs.close(); } return result; } /// <summary> /// xml反序列化 /// </summary> /// <param name="type">目标类型(type类型)</param> /// <param name="filepath">xml文件路径</param> /// <returns>序列对象</returns> public static object deserializefromxml(type type, string filepath) { filestream fs = null; try { fs = new filestream(filepath, filemode.open, fileaccess.read, fileshare.readwrite); xmlserializer serializer = new xmlserializer(type); return serializer.deserialize(fs); } catch (exception ex) { throw ex; } finally { if (fs != null) fs.close(); } } #endregion
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论