示例#1
0
 /// <summary>
 /// 从配置文件反序列化
 /// </summary>
 /// <typeparam name="T">反序列化的目标类型</typeparam>
 /// <param name="fn">键</param>
 /// <returns></returns>
 static object _Load <T>(string fn) where T : class
 {
     try
     {
         var mySerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
         using (var myFileStream = new StreamReader(CHServer.MapPath(fn)).BaseStream)
         {
             return(mySerializer.Deserialize(myFileStream));
         }
     }
     catch
     {
         throw new Exception(string.Format("读取配置文件{0}时出错,编号:{1}", fn, 10358));
     }
 }
示例#2
0
 /// <summary>
 /// 序列化到配置文件 
 /// </summary>
 /// <typeparam name="T">序列化此类型</typeparam>
 /// <param name="obj">要序列化的对象</param>
 /// <param name="fn">键值</param>
 public static void Save <T>(T obj, string fn) where T : class
 {
     try
     {
         var mySerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
         using (var myWriter = new StreamWriter(CHServer.MapPath(fn)))
         {
             mySerializer.Serialize(myWriter, obj);
         }
     }
     catch
     {
         throw new Exception(string.Format("存储配置文件{0}时出错,编号:{1}", fn, 10359));
     }
 }