ningshuxia
2025-03-26 6171f94b5ca6c804ac2892d214943ff0ac400d26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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);
        }
 
 
    }
 
 
}