Exemplo n.º 1
0
        /// <summary>
        /// 可以根据绝对路径得到文件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configPath">配置文件的完整路径</param>
        /// <returns></returns>
        public T GetConfig <T>(string configPath) where T : IConfiger, new()
        {
            string configFilePath = configPath;
            string filename       = typeof(T).Name;

            if (string.IsNullOrWhiteSpace(configFilePath))
            {
                configFilePath = Path.Combine(AppContext.BaseDirectory, string.Format(@"Configs\\{0}.json", filename));
            }

            if (!File.Exists(configFilePath))
            {
                Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "Configs"));
                ConfigSerialize.Serializer(configFilePath, new T());
                LindLogger.LoggerFactory.Logger_Warn("配置文件第一次被建立,文件路径" + configFilePath + "请手动修改相关配置项");
                throw new Exception("配置文件第一次被建立,文件路径" + configFilePath + "请手动修改相关配置项");
            }
            return((T)ConfigFilesManager.Instance.LoadConfig <T>(configFilePath));
        }
Exemplo n.º 2
0
 /// <summary>
 /// 从配置文件中读取
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="type"></param>
 private IConfiger LoadConfigFile <T>(string fileName)
 {
     fileChangeTime[fileName] = File.GetLastWriteTime(fileName);//得到配置文件的最后修改改时间
     return(ConfigSerialize.DeserializeInfo <T>(fileName));
 }