Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataTableCollection.cs
Go to the documentation of this file.
7
8namespace System.Data;
9
10[DefaultEvent("CollectionChanged")]
11[Editor("Microsoft.VSDesigner.Data.Design.TablesCollectionEditor, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
12[ListBindable(false)]
14{
15 private readonly DataSet _dataSet;
16
17 private readonly ArrayList _list = new ArrayList();
18
19 private int _defaultNameIndex = 1;
20
22
23 private CollectionChangeEventHandler _onCollectionChangedDelegate;
24
25 private CollectionChangeEventHandler _onCollectionChangingDelegate;
26
27 private static int s_objectTypeCount;
28
30
31 protected override ArrayList List => _list;
32
33 internal int ObjectID => _objectID;
34
35 public DataTable this[int index]
36 {
37 get
38 {
39 try
40 {
41 return (DataTable)_list[index];
42 }
44 {
46 }
47 }
48 }
49
50 public DataTable? this[string? name]
51 {
52 get
53 {
54 int num = InternalIndexOf(name);
55 if (num == -2)
56 {
58 }
59 if (num == -3)
60 {
62 }
63 if (num >= 0)
64 {
65 return (DataTable)_list[num];
66 }
67 return null;
68 }
69 }
70
71 public DataTable? this[string? name, string tableNamespace]
72 {
73 get
74 {
75 if (tableNamespace == null)
76 {
77 throw ExceptionBuilder.ArgumentNull("tableNamespace");
78 }
79 int num = InternalIndexOf(name, tableNamespace);
80 if (num == -2)
81 {
83 }
84 if (num >= 0)
85 {
86 return (DataTable)_list[num];
87 }
88 return null;
89 }
90 }
91
92 public event CollectionChangeEventHandler? CollectionChanged
93 {
94 add
95 {
96 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.add_CollectionChanged|API> {0}", ObjectID);
98 }
99 remove
100 {
101 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.remove_CollectionChanged|API> {0}", ObjectID);
103 }
104 }
105
106 public event CollectionChangeEventHandler? CollectionChanging
107 {
108 add
109 {
110 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.add_CollectionChanging|API> {0}", ObjectID);
112 }
113 remove
114 {
115 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.remove_CollectionChanging|API> {0}", ObjectID);
117 }
118 }
119
121 {
122 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.DataTableCollection|INFO> {0}, dataSet={1}", ObjectID, dataSet?.ObjectID ?? 0);
124 }
125
126 internal DataTable GetTable(string name, string ns)
127 {
128 for (int i = 0; i < _list.Count; i++)
129 {
131 if (dataTable.TableName == name && dataTable.Namespace == ns)
132 {
133 return dataTable;
134 }
135 }
136 return null;
137 }
138
139 internal DataTable GetTableSmart(string name, string ns)
140 {
141 int num = 0;
142 DataTable result = null;
143 for (int i = 0; i < _list.Count; i++)
144 {
146 if (dataTable.TableName == name)
147 {
148 if (dataTable.Namespace == ns)
149 {
150 return dataTable;
151 }
152 num++;
153 result = dataTable;
154 }
155 }
156 if (num != 1)
157 {
158 return null;
159 }
160 return result;
161 }
162
163 public void Add(DataTable table)
164 {
165 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.Add|API> {0}, table={1}", ObjectID, table?.ObjectID ?? 0);
166 try
167 {
169 BaseAdd(table);
170 ArrayAdd(table);
172 {
173 table.ResetIndexes();
174 }
176 }
177 finally
178 {
179 DataCommonEventSource.Log.ExitScope(scopeId);
180 }
181 }
182
183 public void AddRange(DataTable?[]? tables)
184 {
185 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.AddRange|API> {0}", ObjectID);
186 try
187 {
189 {
191 }
192 else
193 {
194 if (tables == null)
195 {
196 return;
197 }
198 foreach (DataTable dataTable in tables)
199 {
200 if (dataTable != null)
201 {
202 Add(dataTable);
203 }
204 }
205 }
206 }
207 finally
208 {
209 DataCommonEventSource.Log.ExitScope(scopeId);
210 }
211 }
212
213 public DataTable Add(string? name)
214 {
215 DataTable dataTable = new DataTable(name);
216 Add(dataTable);
217 return dataTable;
218 }
219
220 public DataTable Add(string? name, string? tableNamespace)
221 {
223 Add(dataTable);
224 return dataTable;
225 }
226
227 public DataTable Add()
228 {
230 Add(dataTable);
231 return dataTable;
232 }
233
234 private void ArrayAdd(DataTable table)
235 {
236 _list.Add(table);
237 }
238
239 internal string AssignName()
240 {
241 string text = null;
243 {
245 }
246 return text;
247 }
248
249 private void BaseAdd([NotNull] DataTable table)
250 {
251 if (table == null)
252 {
253 throw ExceptionBuilder.ArgumentNull("table");
254 }
255 if (table.DataSet == _dataSet)
256 {
258 }
259 if (table.DataSet != null)
260 {
262 }
263 if (table.TableName.Length == 0)
264 {
265 table.TableName = AssignName();
266 }
267 else
268 {
269 if (NamesEqual(table.TableName, _dataSet.DataSetName, fCaseSensitive: false, _dataSet.Locale) != 0 && !table._fNestedInDataset)
270 {
272 }
273 RegisterName(table.TableName, table.Namespace);
274 }
275 table.SetDataSet(_dataSet);
276 }
277
279 {
280 int num = 0;
281 for (int i = 0; i < oldLength; i++)
282 {
283 bool flag = false;
284 for (int j = num; j < newLength; j++)
285 {
286 if (oldArray[i] == newArray[j])
287 {
288 if (num == j)
289 {
290 num++;
291 }
292 flag = true;
293 break;
294 }
295 }
296 if (!flag && oldArray[i].DataSet == _dataSet)
297 {
299 }
300 }
301 for (int k = 0; k < newLength; k++)
302 {
303 if (newArray[k].DataSet != _dataSet)
304 {
307 }
308 }
309 }
310
311 private void BaseRemove(DataTable table)
312 {
313 if (CanRemove(table, fThrowException: true))
314 {
316 table.SetDataSet(null);
317 }
318 _list.Remove(table);
320 }
321
322 public bool CanRemove(DataTable? table)
323 {
324 return CanRemove(table, fThrowException: false);
325 }
326
327 internal bool CanRemove([NotNullWhen(true)] DataTable table, bool fThrowException)
328 {
329 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.CanRemove|INFO> {0}, table={1}, fThrowException={2}", ObjectID, table?.ObjectID ?? 0, fThrowException);
330 try
331 {
332 if (table == null)
333 {
334 if (!fThrowException)
335 {
336 return false;
337 }
338 throw ExceptionBuilder.ArgumentNull("table");
339 }
340 if (table.DataSet != _dataSet)
341 {
342 if (!fThrowException)
343 {
344 return false;
345 }
347 }
348 _dataSet.OnRemoveTable(table);
349 if (table.ChildRelations.Count != 0 || table.ParentRelations.Count != 0)
350 {
351 if (!fThrowException)
352 {
353 return false;
354 }
356 }
359 {
361 if (foreignKeyConstraint.Table != table || foreignKeyConstraint.RelatedTable != table)
362 {
363 if (!fThrowException)
364 {
365 return false;
366 }
368 }
369 }
372 {
374 if (foreignKeyConstraint2.Table != table || foreignKeyConstraint2.RelatedTable != table)
375 {
376 if (!fThrowException)
377 {
378 return false;
379 }
381 }
382 }
383 return true;
384 }
385 finally
386 {
387 DataCommonEventSource.Log.ExitScope(scopeId);
388 }
389 }
390
391 public void Clear()
392 {
393 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.Clear|API> {0}", ObjectID);
394 try
395 {
396 int count = _list.Count;
398 _list.CopyTo(array, 0);
401 {
403 }
405 _list.Clear();
407 }
408 finally
409 {
410 DataCommonEventSource.Log.ExitScope(scopeId);
411 }
412 }
413
414 public bool Contains(string? name)
415 {
416 return InternalIndexOf(name) >= 0;
417 }
418
419 public bool Contains(string name, string tableNamespace)
420 {
421 if (name == null)
422 {
423 throw ExceptionBuilder.ArgumentNull("name");
424 }
425 if (tableNamespace == null)
426 {
427 throw ExceptionBuilder.ArgumentNull("tableNamespace");
428 }
429 return InternalIndexOf(name, tableNamespace) >= 0;
430 }
431
432 internal bool Contains(string name, string tableNamespace, bool checkProperty, bool caseSensitive)
433 {
434 if (!caseSensitive)
435 {
436 return InternalIndexOf(name) >= 0;
437 }
438 int count = _list.Count;
439 for (int i = 0; i < count; i++)
440 {
442 string text = (checkProperty ? dataTable.Namespace : dataTable._tableNamespace);
443 if (NamesEqual(dataTable.TableName, name, fCaseSensitive: true, _dataSet.Locale) == 1 && text == tableNamespace)
444 {
445 return true;
446 }
447 }
448 return false;
449 }
450
451 internal bool Contains(string name, bool caseSensitive)
452 {
453 if (!caseSensitive)
454 {
455 return InternalIndexOf(name) >= 0;
456 }
457 int count = _list.Count;
458 for (int i = 0; i < count; i++)
459 {
461 if (NamesEqual(dataTable.TableName, name, fCaseSensitive: true, _dataSet.Locale) == 1)
462 {
463 return true;
464 }
465 }
466 return false;
467 }
468
469 public void CopyTo(DataTable[] array, int index)
470 {
471 if (array == null)
472 {
473 throw ExceptionBuilder.ArgumentNull("array");
474 }
475 if (index < 0)
476 {
478 }
479 if (array.Length - index < _list.Count)
480 {
482 }
483 for (int i = 0; i < _list.Count; i++)
484 {
485 array[index + i] = (DataTable)_list[i];
486 }
487 }
488
489 public int IndexOf(DataTable? table)
490 {
491 int count = _list.Count;
492 for (int i = 0; i < count; i++)
493 {
494 if (table == (DataTable)_list[i])
495 {
496 return i;
497 }
498 }
499 return -1;
500 }
501
502 public int IndexOf(string? tableName)
503 {
504 int num = InternalIndexOf(tableName);
505 if (num >= 0)
506 {
507 return num;
508 }
509 return -1;
510 }
511
512 public int IndexOf(string tableName, string tableNamespace)
513 {
515 }
516
517 internal int IndexOf(string tableName, string tableNamespace, bool chekforNull)
518 {
519 if (chekforNull)
520 {
521 if (tableName == null)
522 {
523 throw ExceptionBuilder.ArgumentNull("tableName");
524 }
525 if (tableNamespace == null)
526 {
527 throw ExceptionBuilder.ArgumentNull("tableNamespace");
528 }
529 }
531 if (num >= 0)
532 {
533 return num;
534 }
535 return -1;
536 }
537
543
544 internal int InternalIndexOf(string tableName)
545 {
546 int num = -1;
547 if (tableName != null && 0 < tableName.Length)
548 {
549 int count = _list.Count;
550 int num2 = 0;
551 for (int i = 0; i < count; i++)
552 {
554 switch (NamesEqual(dataTable.TableName, tableName, fCaseSensitive: false, _dataSet.Locale))
555 {
556 case 1:
557 {
558 for (int j = i + 1; j < count; j++)
559 {
561 if (NamesEqual(dataTable2.TableName, tableName, fCaseSensitive: false, _dataSet.Locale) == 1)
562 {
563 return -3;
564 }
565 }
566 return i;
567 }
568 case -1:
569 num = ((num == -1) ? i : (-2));
570 break;
571 }
572 }
573 }
574 return num;
575 }
576
577 internal int InternalIndexOf(string tableName, string tableNamespace)
578 {
579 int num = -1;
580 if (tableName != null && 0 < tableName.Length)
581 {
582 int count = _list.Count;
583 int num2 = 0;
584 for (int i = 0; i < count; i++)
585 {
588 if (num2 == 1 && dataTable.Namespace == tableNamespace)
589 {
590 return i;
591 }
592 if (num2 == -1 && dataTable.Namespace == tableNamespace)
593 {
594 num = ((num == -1) ? i : (-2));
595 }
596 }
597 }
598 return num;
599 }
600
601 internal void FinishInitCollection()
602 {
603 if (_delayedAddRangeTables == null)
604 {
605 return;
606 }
609 {
610 if (dataTable != null)
611 {
612 Add(dataTable);
613 }
614 }
616 }
617
618 private string MakeName(int index)
619 {
620 if (1 != index)
621 {
622 return "Table" + index.ToString(CultureInfo.InvariantCulture);
623 }
624 return "Table1";
625 }
626
628 {
630 {
631 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.OnCollectionChanged|INFO> {0}", ObjectID);
633 }
634 }
635
637 {
639 {
640 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.OnCollectionChanging|INFO> {0}", ObjectID);
642 }
643 }
644
645 internal void RegisterName(string name, string tbNamespace)
646 {
647 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.RegisterName|INFO> {0}, name='{1}', tbNamespace='{2}'", ObjectID, name, tbNamespace);
649 int count = _list.Count;
650 for (int i = 0; i < count; i++)
651 {
653 if (NamesEqual(name, dataTable.TableName, fCaseSensitive: true, locale) != 0 && tbNamespace == dataTable.Namespace)
654 {
655 throw ExceptionBuilder.DuplicateTableName(((DataTable)_list[i]).TableName);
656 }
657 }
659 {
661 }
662 }
663
664 public void Remove(DataTable table)
665 {
666 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.Remove|API> {0}, table={1}", ObjectID, table?.ObjectID ?? 0);
667 try
668 {
670 BaseRemove(table);
672 }
673 finally
674 {
675 DataCommonEventSource.Log.ExitScope(scopeId);
676 }
677 }
678
679 public void RemoveAt(int index)
680 {
681 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.RemoveAt|API> {0}, index={1}", ObjectID, index);
682 try
683 {
684 DataTable dataTable = this[index];
685 if (dataTable == null)
686 {
688 }
690 }
691 finally
692 {
693 DataCommonEventSource.Log.ExitScope(scopeId);
694 }
695 }
696
697 public void Remove(string name)
698 {
699 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTableCollection.Remove|API> {0}, name='{1}'", ObjectID, name);
700 try
701 {
702 DataTable dataTable = this[name];
703 if (dataTable == null)
704 {
706 }
708 }
709 finally
710 {
711 DataCommonEventSource.Log.ExitScope(scopeId);
712 }
713 }
714
715 public void Remove(string name, string tableNamespace)
716 {
717 if (name == null)
718 {
719 throw ExceptionBuilder.ArgumentNull("name");
720 }
721 if (tableNamespace == null)
722 {
723 throw ExceptionBuilder.ArgumentNull("tableNamespace");
724 }
725 DataTable dataTable = this[name, tableNamespace];
726 if (dataTable == null)
727 {
729 }
731 }
732
733 internal void UnregisterName(string name)
734 {
735 DataCommonEventSource.Log.Trace("<ds.DataTableCollection.UnregisterName|INFO> {0}, name='{1}'", ObjectID, name);
737 {
738 do
739 {
741 }
743 }
744 }
745}
virtual void AddRange(ICollection c)
virtual void Remove(object? obj)
virtual int Add(object? value)
virtual void CopyTo(Array array)
static readonly DataCommonEventSource Log
CultureInfo Locale
Definition DataSet.cs:337
virtual void OnRemoveTable(DataTable table)
Definition DataSet.cs:2617
void OnRemovedTable(DataTable table)
Definition DataSet.cs:2621
DataTable Add(string? name, string? tableNamespace)
void RegisterName(string name, string tbNamespace)
bool CanRemove([NotNullWhen(true)] DataTable table, bool fThrowException)
bool Contains(string name, bool caseSensitive)
CollectionChangeEventHandler _onCollectionChangedDelegate
bool Contains(string name, string tableNamespace)
bool Contains(string name, string tableNamespace, bool checkProperty, bool caseSensitive)
void CopyTo(DataTable[] array, int index)
void OnCollectionChanging(CollectionChangeEventArgs ccevent)
void BaseGroupSwitch(DataTable[] oldArray, int oldLength, DataTable[] newArray, int newLength)
CollectionChangeEventHandler? CollectionChanging
void Remove(string name, string tableNamespace)
int IndexOf(string tableName, string tableNamespace, bool chekforNull)
DataTable GetTableSmart(string name, string ns)
int IndexOf(string tableName, string tableNamespace)
void OnCollectionChanged(CollectionChangeEventArgs ccevent)
void AddRange(DataTable?[]? tables)
void ReplaceFromInference(List< DataTable > tableList)
CollectionChangeEventHandler? CollectionChanged
void BaseAdd([NotNull] DataTable table)
DataTable GetTable(string name, string ns)
int InternalIndexOf(string tableName, string tableNamespace)
CollectionChangeEventHandler _onCollectionChangingDelegate
bool SetCaseSensitiveValue(bool isCaseSensitive, bool userSet, bool resetIndexes)
void SetDataSet(DataSet dataSet)
DataRelationCollection ParentRelations
Definition DataTable.cs:572
bool SetLocaleValue(CultureInfo culture, bool userSet, bool resetIndexes)
DataRelationCollection ChildRelations
Definition DataTable.cs:324
static Exception CaseInsensitiveNameConflict(string name)
static Exception TableOutOfRange(int index)
static Exception DatasetConflictingName(string table)
static Exception TableAlreadyInOtherDataSet()
static Exception TableAlreadyInTheDataSet()
static Exception DuplicateTableName(string table)
static Exception ArgumentOutOfRange(string paramName)
static Exception InvalidOffsetLength()
static Exception TableNotInTheDataSet(string table)
static Exception TableInConstraint(DataTable table, Constraint constraint)
static Exception NamespaceNameConflict(string name)
static Exception ArgumentNull(string paramName)
static readonly CollectionChangeEventArgs s_refreshEventArgs
int NamesEqual(string s1, string s2, bool fCaseSensitive, CultureInfo locale)
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
static CultureInfo InvariantCulture
static int Increment(ref int location)
delegate void CollectionChangeEventHandler(object? sender, CollectionChangeEventArgs e)