Esempio n. 1
0
        /// <summary>
        /// 将 Dictionary 序列化为字符串
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        public static String GetDicString(Dictionary <String, String> dic)
        {
            cfgHelper cfg = new cfgHelper();

            cfg.Dic = dic;
            return(cfg.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// 将 Dictionary 对象持久化到磁盘
        /// </summary>
        /// <param name="dic">一个 Dictionary</param>
        /// <param name="path">配置文件的路径(相对路径,相对于项目的根目录)</param>
        /// <param name="separator">键和值之间的分隔符</param>
        public static void Write(Dictionary <String, String> dic, String path, char separator)
        {
            if (strUtil.IsNullOrEmpty(path))
            {
                throw new IOException("config path is empty");
            }

            cfgHelper cfg = new cfgHelper();

            cfg.Dic = dic;
            cfg.setSeparator(separator);

            file.Write(PathHelper.Map(path), cfg.Content);
        }
Esempio n. 3
0
        /// <summary>
        /// 读取配置文件,返回一个 Dictionary,键值都是字符串
        /// </summary>
        /// <param name="path">配置文件的路径(相对路径,相对于项目的根目录)</param>
        /// <param name="separator">键和值之间的分隔符</param>
        /// <returns>返回一个 Dictionary</returns>
        public static Dictionary <String, String> Read(String absPath, char separator)
        {
            if (strUtil.IsNullOrEmpty(absPath))
            {
                throw new IOException("config path is empty");
            }

            cfgHelper cfg = new cfgHelper();

            try {
                cfg.Content = file.Read(absPath);
            }
            catch (IOException) {
                cfg.Content = "";
            }

            return(cfg.toDic(separator));
        }