/// <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(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"Configs\\{0}.json", filename)); } if (!File.Exists(configFilePath)) { Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs")); ConfigSerialize.Serializer(configFilePath, new T()); Logger.LoggerFactory.Instance.Logger_Warn("配置文件第一次被建立,文件路径" + configFilePath + "请手动修改相关配置项"); throw new Exception("配置文件第一次被建立,文件路径" + configFilePath + "请手动修改相关配置项"); } return((T)ConfigFilesManager.Instance.LoadConfig <T>(configFilePath)); }
/// <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)); }