Пример #1
0
        /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="obj">对象</param>
        /// <param name="path">文件路径</param>
        public static void Save(object obj, string path)
        {
            Stream stream = null;

            try
            {
                stream = new MemoryStream();
                XmlSerializer serializer = new XmlSerializer(obj.GetType());
                serializer.Serialize(stream, obj);
                //XOR.EncryptAndSave(stream, path);
                Utils.SaveStreamToFile(stream, path);
                //XOR.EncryptAndSave(stream, path);//异或加密
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }