Exemple #1
0
        /// <summary>
        /// 从文件读取对象
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <return>对象</return>
        public static object ReadObjectFromFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(null);
            }

            using (SafeFileStream fileStream = new SafeFileStream(fileName, FileMode.Open, FileAccess.Read)) {
                object obj = ReadObjectFromStream(fileStream);
                return(obj);
            }
        }
Exemple #2
0
 /// <summary>
 /// 保存对象到文件
 /// </summary>
 /// <param name="fileName">文件名</param>
 /// <param name="obj">对象</param>
 public static void WriteObjectToFile(string fileName, object obj)
 {
     using (SafeFileStream fileStream = new SafeFileStream(fileName, FileMode.Create, FileAccess.Write)) {
         WriteObjectToStream(fileStream, obj);
     }
 }