Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataRowCollection.cs
Go to the documentation of this file.
2
3namespace System.Data;
4
6{
7 private sealed class DataRowTree : RBTree<DataRow>
8 {
9 internal DataRowTree()
11 {
12 }
13
14 protected override int CompareNode(DataRow record1, DataRow record2)
15 {
16 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.CompareNodeInDataRowTree);
17 }
18
19 protected override int CompareSateliteTreeNode(DataRow record1, DataRow record2)
20 {
21 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.CompareSateliteTreeNodeInDataRowTree);
22 }
23 }
24
25 private readonly DataTable _table;
26
27 private readonly DataRowTree _list = new DataRowTree();
28
29 internal int _nullInList;
30
31 public override int Count => _list.Count;
32
33 public DataRow this[int index] => _list[index];
34
36 {
37 _table = table;
38 }
39
40 public void Add(DataRow row)
41 {
42 _table.AddRow(row, -1);
43 }
44
45 public void InsertAt(DataRow row, int pos)
46 {
47 if (pos < 0)
48 {
50 }
51 if (pos >= _list.Count)
52 {
53 _table.AddRow(row, -1);
54 }
55 else
56 {
57 _table.InsertRow(row, -1, pos);
58 }
59 }
60
61 internal void DiffInsertAt(DataRow row, int pos)
62 {
63 if (pos < 0 || pos == _list.Count)
64 {
65 _table.AddRow(row, (pos > -1) ? (pos + 1) : (-1));
66 }
67 else if (_table.NestedParentRelations.Length != 0)
68 {
69 if (pos < _list.Count)
70 {
71 if (_list[pos] != null)
72 {
74 }
75 _list.RemoveAt(pos);
77 _table.InsertRow(row, pos + 1, pos);
78 }
79 else
80 {
81 while (pos > _list.Count)
82 {
83 _list.Add(null);
85 }
86 _table.AddRow(row, pos + 1);
87 }
88 }
89 else
90 {
91 _table.InsertRow(row, pos + 1, (pos > _list.Count) ? (-1) : pos);
92 }
93 }
94
95 public int IndexOf(DataRow? row)
96 {
97 if (row != null && row.Table == _table && (row.RBTreeNodeId != 0 || row.RowState != DataRowState.Detached))
98 {
99 return _list.IndexOf(row.RBTreeNodeId, row);
100 }
101 return -1;
102 }
103
104 internal DataRow AddWithColumnEvents(params object[] values)
105 {
106 DataRow dataRow = _table.NewRow(-1);
107 dataRow.ItemArray = values;
108 _table.AddRow(dataRow, -1);
109 return dataRow;
110 }
111
112 public DataRow Add(params object?[] values)
113 {
114 int record = _table.NewRecordFromArray(values);
115 DataRow dataRow = _table.NewRow(record);
116 _table.AddRow(dataRow, -1);
117 return dataRow;
118 }
119
120 internal void ArrayAdd(DataRow row)
121 {
122 row.RBTreeNodeId = _list.Add(row);
123 }
124
125 internal void ArrayInsert(DataRow row, int pos)
126 {
127 row.RBTreeNodeId = _list.Insert(pos, row);
128 }
129
130 internal void ArrayClear()
131 {
132 _list.Clear();
133 }
134
135 internal void ArrayRemove(DataRow row)
136 {
137 if (row.RBTreeNodeId == 0)
138 {
139 throw ExceptionBuilder.InternalRBTreeError(RBTreeError.AttachedNodeWithZerorbTreeNodeId);
140 }
142 row.RBTreeNodeId = 0;
143 }
144
145 public DataRow? Find(object? key)
146 {
148 }
149
150 public DataRow? Find(object?[] keys)
151 {
153 }
154
155 public void Clear()
156 {
157 _table.Clear(clearAll: false);
158 }
159
160 public bool Contains(object? key)
161 {
162 return _table.FindByPrimaryKey(key) != null;
163 }
164
165 public bool Contains(object?[] keys)
166 {
167 return _table.FindByPrimaryKey(keys) != null;
168 }
169
170 public override void CopyTo(Array ar, int index)
171 {
172 _list.CopyTo(ar, index);
173 }
174
175 public void CopyTo(DataRow[] array, int index)
176 {
178 }
179
180 public override IEnumerator GetEnumerator()
181 {
182 return _list.GetEnumerator();
183 }
184
185 public void Remove(DataRow row)
186 {
187 if (row == null || row.Table != _table || -1 == row.rowID)
188 {
190 }
191 if (row.RowState != DataRowState.Deleted && row.RowState != DataRowState.Detached)
192 {
193 row.Delete();
194 }
195 if (row.RowState != DataRowState.Detached)
196 {
197 row.AcceptChanges();
198 }
199 }
200
201 public void RemoveAt(int index)
202 {
203 Remove(this[index]);
204 }
205}
override int CompareNode(DataRow record1, DataRow record2)
override int CompareSateliteTreeNode(DataRow record1, DataRow record2)
DataRow? Find(object?[] keys)
override IEnumerator GetEnumerator()
void DiffInsertAt(DataRow row, int pos)
void InsertAt(DataRow row, int pos)
DataRow Add(params object?[] values)
void CopyTo(DataRow[] array, int index)
DataRow AddWithColumnEvents(params object[] values)
override void CopyTo(Array ar, int index)
void ArrayInsert(DataRow row, int pos)
DataTable Table
Definition DataRow.cs:169
DataRowState RowState
Definition DataRow.cs:134
void InsertRow(DataRow row, int proposedID, int pos)
int NewRecordFromArray(object[] value)
DataRow FindByPrimaryKey(object[] values)
void AddRow(DataRow row)
DataRelation[] NestedParentRelations
Definition DataTable.cs:586
static Exception RowInsertTwice(int index, string tableName)
static Exception InternalRBTreeError(RBTreeError internalError)
static Exception RowInsertOutOfRange(int index)
int IndexOf(int nodeId, K item)
Definition RBTree.cs:1237
int Add(K item)
Definition RBTree.cs:1225
int RBDelete(int z_id)
Definition RBTree.cs:754
void CopyTo(Array array, int index)
Definition RBTree.cs:1280
void RemoveAt(int position)
Definition RBTree.cs:1269
IEnumerator GetEnumerator()
Definition RBTree.cs:1232
int Insert(K item)
Definition RBTree.cs:1218