namespace HydroUI
|
{
|
|
|
[Serializable]
|
public class NodeViewModelList : List<NodeCalcModel>
|
{
|
Dictionary<string, NodeCalcModel> dict;
|
public NodeViewModelList() : base()
|
{
|
this.dict = new Dictionary<string, NodeCalcModel>();
|
}
|
|
|
public void ChangeID(string oldID, string newID)
|
{
|
if (dict.ContainsKey(oldID))
|
{
|
dict[oldID].ID = newID;
|
dict.Add(newID, dict[oldID]);
|
dict.Remove(oldID);
|
}
|
}
|
|
/// 实现Add方法,同时更新字典
|
public void Add(NodeViewModel nodeCalcModel)
|
{
|
base.Add(nodeCalcModel);
|
if (!dict.ContainsKey(nodeCalcModel.ID))
|
dict.Add(nodeCalcModel.ID, nodeCalcModel);
|
}
|
|
/// 实现AddRange方法,同时更新字典
|
/// <param name="nodeCalcModels"></param>
|
public void AddRange(List<NodeViewModel> nodeCalcModels)
|
{
|
base.AddRange(nodeCalcModels);
|
nodeCalcModels.ForEach(node =>
|
{
|
if (!dict.ContainsKey(node.ID))
|
dict.Add(node.ID, node);
|
});
|
}
|
|
/// 实现Remove方法,同时更新字典
|
public bool Remove(NodeViewModel nodeCalcModel)
|
{
|
if (base.Remove(nodeCalcModel))
|
{
|
if (dict.ContainsKey(nodeCalcModel.ID))
|
dict.Remove(nodeCalcModel.ID);
|
return true;
|
}
|
else
|
return false;
|
}
|
|
|
/// 统计数量
|
public int Count { get { return base.Count; } }
|
public NodeViewModel this[string ID]
|
{
|
get
|
{
|
if (dict.ContainsKey(ID))
|
return (NodeViewModel)dict[ID];
|
else
|
return (NodeViewModel)base.Find(l => l.ID == ID);
|
}
|
}
|
public NodeViewModel this[int index]
|
{
|
get
|
{
|
return (NodeViewModel)base[index];
|
}
|
}
|
|
public List<NodeViewModel> ViewNodes
|
{
|
get
|
{
|
List<NodeViewModel> list = new List<NodeViewModel>();
|
foreach (var item in this)
|
{
|
list.Add((NodeViewModel)item);
|
}
|
return list;
|
}
|
|
}
|
|
|
|
public NodeViewModel Find(Predicate<NodeViewModel> match)
|
{
|
return ViewNodes.Find(match);
|
}
|
//实现FindAll方法
|
public List<NodeViewModel> FindAll(Predicate<NodeViewModel> match)
|
{
|
return ViewNodes.FindAll(match);
|
}
|
//实现ForEach方法
|
public void ForEach(Action<NodeViewModel> action)
|
{
|
ViewNodes.ForEach(action);
|
}
|
|
|
}
|
|
|
}
|