您的位置:首页 > 教育 > 锐评 > 莱州网络推广公司_泰安公司_最佳的资源磁力搜索引擎_用网站模板建站

莱州网络推广公司_泰安公司_最佳的资源磁力搜索引擎_用网站模板建站

2025/1/4 4:07:15 来源:https://blog.csdn.net/lzhdim/article/details/144798198  浏览:    关键词:莱州网络推广公司_泰安公司_最佳的资源磁力搜索引擎_用网站模板建站
莱州网络推广公司_泰安公司_最佳的资源磁力搜索引擎_用网站模板建站

       此文记录的是XML文件的序列化和反序列化工具类。

/***XML工具类Austin Liu 刘恒辉Project Manager and Software DesignerE-Mail: lzhdim@163.comBlog:   http://lzhdim.cnblogs.comDate:   2024-01-15 15:18:00使用说明:/// <summary>/// 加载程序函数/// </summary>/// <param name="appConfigFilePath"></param>/// <returns></returns>internal static AppConfigModule LoadSetting(string appConfigFilePath){AppConfigModule list;try{list = (AppConfigModule)XMLUtil.Deserialize(new AppConfigModule(), FileUtil.ReadFile(appConfigFilePath));}catch{return null;}return list;}/// <summary>/// 保存程序函数/// </summary>/// <param name="ListProgram"></param>/// <param name="appConfigFilePath"></param>internal static void SaveSetting(AppConfigModule ListProgram, string appConfigFilePath){FileUtil.SaveFile(appConfigFilePath, XMLUtil.Serialize(ListProgram));}***/namespace Lzhdim.LPF.Utility
{using System;using System.IO;using System.Xml.Serialization;/// <summary>/// The Object End of XML/// </summary>public static class XMLUtil{/// <summary>/// Deserialize string to an object/// </summary>/// <param name="obj">the object which need to Deserialize</param>/// <param name="serializedString">string which need to Deserialize</param>/// <returns>Object</returns>public static Object Deserialize(Object obj, string serializedString){XmlSerializer xsw = new XmlSerializer(obj.GetType());TextReader s = new StringReader(serializedString);return xsw.Deserialize(s);}/// <summary>/// Deserialize string to an object/// </summary>/// <param name="objectType">the Type of object which need to Deserialize</param>/// <param name="serializedString">string which need to Deserialize</param>/// <returns>Object</returns>public static Object Deserialize(Type objectType, string serializedString){XmlSerializer xsw = new XmlSerializer(objectType);TextReader s = new StringReader(serializedString);return xsw.Deserialize(s);}/// <summary>/// Deserialize string to an object/// </summary>/// <param name="serializedString">string which need to Deserialize</param>/// <param name="listType">the Type of object which need to Deserialize</param>/// <param name="elementType">the element type of the objectlist</param>/// <returns>object</returns>public static Object Deserialize(string serializedString, Type listType, Type elementType){XmlSerializer serializer = new XmlSerializer(listType, new Type[] { elementType });StringReader textReader = new StringReader(serializedString);return serializer.Deserialize(textReader);}/// <summary>/// Serialize an object to string/// </summary>/// <param name="obj">object which need to Serialize</param>/// <returns>string</returns>public static string Serialize(Object obj){XmlSerializer serializer = new XmlSerializer(obj.GetType());StringWriter writer = new StringWriter();serializer.Serialize((TextWriter)writer, obj);return writer.ToString();}/// <summary>/// Serialize an object to string/// </summary>/// <param name="objList">object which need to Serialize</param>/// <param name="elementType">the element type of the objectlist</param>/// <returns></returns>public static string Serialize(object objList, Type elementType){XmlSerializer serializer = new XmlSerializer(objList.GetType(), new Type[] { elementType });StringWriter writer = new StringWriter();serializer.Serialize((TextWriter)writer, objList);return writer.ToString();}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com