/// <summary> /// 添加后Id会得到新的值 /// </summary> /// <param name="item"></param> public static void Add(T item) { int l = Count; if (l == 0) { item.Id = 1; } else { item.Id = ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List[Count - 1].Id + 1; } //IndexById.Add(item.Id, item); //if (!IndexByName.ContainsKey(item.Name)) //{ // IndexByName.Add(item.Name, new List<T>() { item }); //} //else // IndexByName[item.Name].Add(item); //if (!IndexByParentId.ContainsKey(item.ParentId)) //{ // IndexByParentId.Add(item.ParentId, new List<T>() { item }); //} //else // IndexByParentId[item.ParentId].Add(item); ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List.Add(item); ConfigFileManager.SaveConfig <ParentConfigCollection <T> >(); BuildIndex(); }
/// <summary> /// 建立索引 /// </summary> protected static void BuildIndex() { IndexById.Clear(); IndexByName.Clear(); IndexByParentId.Clear(); foreach (T item in ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List) { IndexById.Add(item.Id, item); if (!IndexByName.ContainsKey(item.Name)) { IndexByName.Add(item.Name, new List <T>() { item }); } else { IndexByName[item.Name].Add(item); } if (!IndexByParentId.ContainsKey(item.ParentId)) { IndexByParentId.Add(item.ParentId, new List <T>() { item }); } else { IndexByParentId[item.ParentId].Add(item); } } }
public static void Clear() { IndexById.Clear(); IndexByName.Clear(); IndexByParentId.Clear(); ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List.Clear(); }
/// <summary> /// 建立索引 /// </summary> protected static void BuildIndex() { IndexByName.Clear(); foreach (T item in ConfigFileManager.GetConfig <NameConfigCollection <T> >().List) { IndexByName.Add(item.Name, item); } }
public static bool Remove(T item) { bool ret = false; if (Contains(item)) { ret = ConfigFileManager.GetConfig <NameConfigCollection <T> >().List.Remove(item); IndexByName.Remove(item.Name); } return(ret); }
/// <summary> /// 更新 /// </summary> /// <param name="item"></param> public static void Update(T item) { T ordinaryItem = Get(item.Id); if (!ordinaryItem.Equals(item)) { int pos = ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List.IndexOf(ordinaryItem); ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List[pos] = item; } ConfigFileManager.SaveConfig <ParentConfigCollection <T> >(); BuildIndex(); }
/// <summary> /// 添加后Id会得到新的值 /// </summary> /// <param name="item"></param> public static void Add(T item) { var config = ConfigFileManager.GetConfig <IdConfigCollection <T> >(); int l = Count; if (l == 0) { item.Id = 1; } else { item.Id = config.List[Count - 1].Id + 1; } IndexById.Add(item.Id, item); config.List.Add(item); }
public static bool Remove(T item) { bool ret = false; if (Contains(item)) { ret = ConfigFileManager.GetConfig <IdNameConfigCollection <T> >().List.Remove(item); //IndexById.Remove(item.Id); //if (!IndexByName.ContainsKey(item.Name)) //{ // IndexByName.Add(item.Name, new List<T> { item }); //} //else // IndexByName[item.Name].Add(item); ConfigFileManager.SaveConfig <IdNameConfigCollection <T> >(); BuildIndex(); } return(ret); }
public static bool Remove(T item) { bool ret = false; if (Contains(item)) { ret = ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List.Remove(item); ConfigFileManager.SaveConfig <ParentConfigCollection <T> >(); BuildIndex(); //IndexById.Remove(item.Id); //IndexByName[item.Name].Remove(item); //if (IndexByName[item.Name].Count == 0) //{ // IndexByName.Remove(item.Name); //} //IndexByParentId[item.ParentId].Remove(item); //if (IndexByParentId[item.ParentId].Count == 0) //{ // IndexByParentId.Remove(item.ParentId); //} } return(ret); }
/// <summary> /// 反会所有 /// </summary> public static ReadOnlyCollection <T> ListAll() { return(ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List.AsReadOnly()); }
public static IEnumerator <T> GetEnumerator() { return(ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List.GetEnumerator()); }
public static bool Contains(T item) { return(ConfigFileManager.GetConfig <ParentConfigCollection <T> >().List.Contains(item)); }
/// <summary> /// 添加后Id会得到新的值 /// </summary> /// <param name="item"></param> public static void Add(T item) { IndexByName.Add(item.Name, item); ConfigFileManager.GetConfig <NameConfigCollection <T> >().List.Add(item); }
public static void Clear() { IndexById.Clear(); ConfigFileManager.GetConfig <IdConfigCollection <T> >().List.Clear(); }