public void UpdateFromFolder(string folder = null) { this.Folder = folder == null ? this.Folder : folder;//Folder不得為空, 所以傳空值就保留原本的 this.LastUpdate = DateTime.Now; //記錄現有的 var orignalConfigs = new Dictionary <String, Boolean>(); foreach (var name in this.Keys) { orignalConfigs[name] = false; } var di = new DirectoryInfo(this.Folder); if (!di.Exists) { di.Create(); } foreach (var fi in di.GetFiles()) { if (this.Filter != null) { if (!Filter(fi.Name)) { continue; //沒通過就不加入 } } var config = CtkUtil.LoadXmlOrNew <T>(fi.FullName); this[fi.Name] = config; //更新存在的 orignalConfigs[fi.Name] = true; } //移除沒更新到的 foreach (var kv in orignalConfigs) { if (kv.Value) { continue; } this.Remove(kv.Key); } }
public static T LoadXml <T>(string fn) where T : class, new() { return(CtkUtil.LoadXmlOrNew <T>(fn)); }