/// <summary>
        /// 保存序列化对象
        /// </summary>
        /// <param name="path">保存路径</param>
        /// <param name="Iconfiginfo">被保存的对象</param>
        /// <returns></returns>
        public static bool Serializer(string path, IConfiger Iconfiginfo)
        {
            bool          success    = false;
            FileStream    fs         = null;
            XmlSerializer serializer = null;

            try
            {
                string sPath = Path.GetDirectoryName(path);
                if (!Directory.Exists(sPath))
                {
                    //没有指定文件夹就生成指定文件夹
                    Directory.CreateDirectory(sPath);
                }

                fs         = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                serializer = new XmlSerializer(Iconfiginfo.GetType());
                serializer.Serialize(fs, Iconfiginfo);
                success = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
            return(success);
        }
        /// <summary>
        /// 保存(序列化)指定路径下的配置文件
        /// </summary>
        /// <param name="configFilePath">指定的配置文件所在的路径(包括文件名)</param>
        /// <param name="configinfo">被保存(序列化)的对象</param>
        /// <returns></returns>
        public static bool Serializer(string path, IConfiger Iconfiginfo)
        {
            bool succeed = false;
            FileStream fs = null;
            XmlSerializer serializer = null;
            try
            {
                fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                serializer = new XmlSerializer(Iconfiginfo.GetType());
                serializer.Serialize(fs, Iconfiginfo);
                //成功则将会返回true
                succeed = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                    serializer = null;
                }
            }

            return succeed;
        }
Exemple #3
0
        /// <summary>
        /// 保存(序列化)指定路径下的配置文件
        /// </summary>
        /// <param name="configFilePath">指定的配置文件所在的路径(包括文件名)</param>
        /// <param name="configinfo">被保存(序列化)的对象</param>
        /// <returns></returns>
        public static bool Serializer(string path, IConfiger Iconfiginfo)
        {
            bool          succeed    = false;
            FileStream    fs         = null;
            XmlSerializer serializer = null;

            try
            {
                fs         = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                serializer = new XmlSerializer(Iconfiginfo.GetType());
                serializer.Serialize(fs, Iconfiginfo);
                //成功则将会返回true
                succeed = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                    serializer = null;
                }
            }

            return(succeed);
        }
        /// <summary>
        /// 写入配置文件
        /// </summary>
        /// <param name="configPath">路径</param>
        /// <param name="iConfiger">对象</param>
        /// <returns></returns>
        public bool WriteConfig(string configPath, IConfiger iConfiger)
        {
            string configFilePath = GetConfigPath(configPath, iConfiger.GetType().Name);

            return(ConfigFilesManager.Instance.WriteConfig(configFilePath, iConfiger));
        }