Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataView.cs
Go to the documentation of this file.
7using System.Text;
9
10namespace System.Data;
11
12[Designer("Microsoft.VSDesigner.Data.VS.DataViewDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
13[DefaultProperty("Table")]
14[DefaultEvent("PositionChanged")]
15[Editor("Microsoft.VSDesigner.Data.Design.DataSourceEditor, 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")]
17{
18 private sealed class DataRowReferenceComparer : IEqualityComparer<DataRow>
19 {
21
23 {
24 }
25
26 public bool Equals(DataRow x, DataRow y)
27 {
28 return x == y;
29 }
30
32 {
33 return obj._objectID;
34 }
35 }
36
37 private sealed class RowPredicateFilter : IFilter
38 {
40
42 {
43 _predicateFilter = predicate;
44 }
45
47 {
48 return _predicateFilter(row);
49 }
50 }
51
53
55
56 private bool _locked;
57
58 private Index _index;
59
61
62 private string _sort = string.Empty;
63
65
67
69
70 private bool _shouldOpen = true;
71
72 private bool _open;
73
74 private bool _allowNew = true;
75
76 private bool _allowEdit = true;
77
78 private bool _allowDelete = true;
79
80 private bool _applyDefaultSort;
81
83
85
86 private ListChangedEventHandler _onListChanged;
87
89
91
92 private string _delayedRowFilter;
93
94 private string _delayedSort;
95
97
98 private bool _fInitInProgress;
99
101
103
105
107
108 private static int s_objectTypeCount;
109
111
112 [DefaultValue(true)]
113 public bool AllowDelete
114 {
115 get
116 {
117 return _allowDelete;
118 }
119 set
120 {
121 if (_allowDelete != value)
122 {
125 }
126 }
127 }
128
130 [DefaultValue(false)]
132 {
133 get
134 {
135 return _applyDefaultSort;
136 }
137 set
138 {
139 DataCommonEventSource.Log.Trace("<ds.DataView.set_ApplyDefaultSort|API> {0}, {1}", ObjectID, value);
141 {
142 _comparison = null;
144 UpdateIndex(force: true);
146 }
147 }
148 }
149
150 [DefaultValue(true)]
151 public bool AllowEdit
152 {
153 get
154 {
155 return _allowEdit;
156 }
157 set
158 {
159 if (_allowEdit != value)
160 {
163 }
164 }
165 }
166
167 [DefaultValue(true)]
168 public bool AllowNew
169 {
170 get
171 {
172 return _allowNew;
173 }
174 set
175 {
176 if (_allowNew != value)
177 {
180 }
181 }
182 }
183
184 [Browsable(false)]
185 public int Count => _rowViewCache.Count;
186
187 private int CountFromIndex => ((_index != null) ? _index.RecordCount : 0) + ((_addNewRow != null) ? 1 : 0);
188
189 [Browsable(false)]
191
192 [Browsable(false)]
194
195 [Browsable(false)]
196 protected bool IsOpen => _open;
197
198 bool ICollection.IsSynchronized => false;
199
200 [DefaultValue("")]
201 public virtual string? RowFilter
202 {
203 get
204 {
206 {
207 return dataExpression.Expression;
208 }
209 return "";
210 }
211 [RequiresUnreferencedCode("Members of types used in the filter expression might be trimmed.")]
212 set
213 {
214 if (value == null)
215 {
216 value = string.Empty;
217 }
218 DataCommonEventSource.Log.Trace("<ds.DataView.set_RowFilter|API> {0}, '{1}'", ObjectID, value);
220 {
222 return;
223 }
225 if (_rowFilter == null || string.Compare(RowFilter, value, ignoreCase: false, culture) != 0)
226 {
229 }
230 }
231 }
232
234 {
235 get
236 {
238 {
239 return null;
240 }
241 return rowPredicateFilter._predicateFilter;
242 }
243 set
244 {
245 if ((object)RowPredicate != value)
246 {
247 SetIndex(Sort, RowStateFilter, (value != null) ? new RowPredicateFilter(value) : null);
248 }
249 }
250 }
251
252 [DefaultValue(DataViewRowState.CurrentRows)]
254 {
255 get
256 {
257 return _recordStates;
258 }
259 set
260 {
261 DataCommonEventSource.Log.Trace("<ds.DataView.set_RowStateFilter|API> {0}, {1}", ObjectID, value);
263 {
265 return;
266 }
267 if (((uint)value & 0xFFFFFFC1u) != 0)
268 {
270 }
271 if ((value & DataViewRowState.ModifiedOriginal) != 0 && (value & DataViewRowState.ModifiedCurrent) != 0)
272 {
274 }
275 if (_recordStates != value)
276 {
278 }
279 }
280 }
281
282 [DefaultValue("")]
283 public string Sort
284 {
285 get
286 {
287 if (_sort.Length == 0 && _applyDefaultSort && _table != null && _table._primaryIndex.Length != 0)
288 {
290 }
291 return _sort;
292 }
294 set
295 {
296 if (value == null)
297 {
298 value = string.Empty;
299 }
300 DataCommonEventSource.Log.Trace("<ds.DataView.set_Sort|API> {0}, '{1}'", ObjectID, value);
302 {
304 return;
305 }
307 if (string.Compare(_sort, value, ignoreCase: false, culture) != 0 || _comparison != null)
308 {
310 _comparison = null;
312 }
313 }
314 }
315
317 {
318 get
319 {
320 return _comparison;
321 }
322 set
323 {
324 DataCommonEventSource.Log.Trace("<ds.DataView.set_SortComparison|API> {0}", ObjectID);
325 if ((object)_comparison != value)
326 {
329 }
330 }
331 }
332
333 object ICollection.SyncRoot => this;
334
336 [DefaultValue(null)]
339 {
340 get
341 {
342 return _table;
343 }
344 set
345 {
346 DataCommonEventSource.Log.Trace("<ds.DataView.set_Table|API> {0}, {1}", ObjectID, value?.ObjectID ?? 0);
347 if (_fInitInProgress && value != null)
348 {
350 return;
351 }
352 if (_locked)
353 {
355 }
356 if (_dataViewManager != null)
357 {
359 }
360 if (value != null && value.TableName.Length == 0)
361 {
363 }
364 if (_table != value)
365 {
367 _table = value;
368 if (_table != null)
369 {
371 }
372 SetIndex2("", DataViewRowState.CurrentRows, null, fireEvent: false);
373 if (_table != null)
374 {
376 }
378 }
379 }
380 }
381
382 object? IList.this[int recordIndex]
383 {
384 get
385 {
386 return this[recordIndex];
387 }
388 set
389 {
391 }
392 }
393
395
396 bool IList.IsReadOnly => false;
397
398 bool IList.IsFixedSize => false;
399
400 bool IBindingList.AllowNew => AllowNew;
401
402 bool IBindingList.AllowEdit => AllowEdit;
403
404 bool IBindingList.AllowRemove => AllowDelete;
405
406 bool IBindingList.SupportsChangeNotification => true;
407
408 bool IBindingList.SupportsSearching => true;
409
410 bool IBindingList.SupportsSorting => true;
411
412 bool IBindingList.IsSorted => Sort.Length != 0;
413
414 PropertyDescriptor? IBindingList.SortProperty => GetSortProperty();
415
416 ListSortDirection IBindingList.SortDirection
417 {
418 get
419 {
420 if (_index._indexFields.Length != 1 || !_index._indexFields[0].IsDescending)
421 {
422 return ListSortDirection.Ascending;
423 }
424 return ListSortDirection.Descending;
425 }
426 }
427
428 string? IBindingListView.Filter
429 {
430 get
431 {
432 return RowFilter;
433 }
434 [RequiresUnreferencedCode("Members of types used in the filter expression might be trimmed.")]
435 set
436 {
438 }
439 }
440
441 ListSortDescriptionCollection IBindingListView.SortDescriptions => GetSortDescriptions();
442
443 bool IBindingListView.SupportsAdvancedSorting => true;
444
445 bool IBindingListView.SupportsFiltering => true;
446
447 internal int ObjectID => _objectID;
448
449 public event ListChangedEventHandler? ListChanged
450 {
451 add
452 {
453 DataCommonEventSource.Log.Trace("<ds.DataView.add_ListChanged|API> {0}", ObjectID);
455 }
456 remove
457 {
458 DataCommonEventSource.Log.Trace("<ds.DataView.remove_ListChanged|API> {0}", ObjectID);
460 }
461 }
462
463 public event EventHandler? Initialized;
464
465 internal DataView(DataTable table, bool locked)
466 {
467 GC.SuppressFinalize(this);
468 DataCommonEventSource.Log.Trace("<ds.DataView.DataView|INFO> {0}, table={1}, locked={2}", ObjectID, table?.ObjectID ?? 0, locked);
469 _dvListener = new DataViewListener(this);
470 _locked = locked;
471 _table = table;
473 }
474
475 public DataView()
476 : this(null)
477 {
478 SetIndex2("", DataViewRowState.CurrentRows, null, fireEvent: true);
479 }
480
481 public DataView(DataTable? table)
482 : this(table, locked: false)
483 {
484 SetIndex2("", DataViewRowState.CurrentRows, null, fireEvent: true);
485 }
486
487 [RequiresUnreferencedCode("Members of types used in the filter expression might be trimmed.")]
488 public DataView(DataTable table, string? RowFilter, string? Sort, DataViewRowState RowState)
489 {
490 GC.SuppressFinalize(this);
491 DataCommonEventSource.Log.Trace("<ds.DataView.DataView|API> {0}, table={1}, RowFilter='{2}', Sort='{3}', RowState={4}", ObjectID, table?.ObjectID ?? 0, RowFilter, Sort, RowState);
492 if (table == null)
493 {
495 }
496 _dvListener = new DataViewListener(this);
497 _locked = false;
498 _table = table;
500 if (((uint)RowState & 0xFFFFFFC1u) != 0)
501 {
503 }
504 if ((RowState & DataViewRowState.ModifiedOriginal) != 0 && (RowState & DataViewRowState.ModifiedCurrent) != 0)
505 {
507 }
508 if (Sort == null)
509 {
510 Sort = string.Empty;
511 }
512 if (RowFilter == null)
513 {
514 RowFilter = string.Empty;
515 }
517 SetIndex(Sort, RowState, newRowFilter);
518 }
519
521 {
522 GC.SuppressFinalize(this);
523 DataCommonEventSource.Log.Trace("<ds.DataView.DataView|API> %d#, table=%d, RowState=%d{ds.DataViewRowState}\n", ObjectID, table?.ObjectID ?? 0, (int)RowState);
524 if (table == null)
525 {
527 }
528 _dvListener = new DataViewListener(this);
529 _locked = false;
530 _table = table;
532 if (((uint)RowState & 0xFFFFFFC1u) != 0)
533 {
535 }
536 if ((RowState & DataViewRowState.ModifiedOriginal) != 0 && (RowState & DataViewRowState.ModifiedCurrent) != 0)
537 {
539 }
541 SetIndex2("", RowState, (predicate != null) ? new RowPredicateFilter(predicate) : null, fireEvent: true);
542 }
543
544 public virtual DataRowView AddNew()
545 {
546 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataView.AddNew|API> {0}", ObjectID);
547 try
548 {
549 CheckOpen();
550 if (!AllowNew)
551 {
553 }
554 if (_addNewRow != null)
555 {
556 _rowViewCache[_addNewRow].EndEdit();
557 }
562 return dataRowView;
563 }
564 finally
565 {
566 DataCommonEventSource.Log.ExitScope(scopeId);
567 }
568 }
569
570 public void BeginInit()
571 {
572 _fInitInProgress = true;
573 }
574
575 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Warning related to RowFilter has already been shown when RowFilter was delay set.")]
576 public void EndInit()
577 {
579 {
581 return;
582 }
583 _fInitInProgress = false;
584 _fEndInitInProgress = true;
585 if (_delayedTable != null)
586 {
588 _delayedTable = null;
589 }
590 if (_delayedSort != null)
591 {
593 _delayedSort = null;
594 }
595 if (_delayedRowFilter != null)
596 {
598 _delayedRowFilter = null;
599 }
601 {
604 }
605 _fEndInitInProgress = false;
608 }
609
610 private void CheckOpen()
611 {
612 if (!IsOpen)
613 {
615 }
616 }
617
618 private void CheckSort(string sort)
619 {
620 if (_table == null)
621 {
623 }
624 if (sort.Length != 0)
625 {
627 }
628 }
629
630 protected void Close()
631 {
632 _shouldOpen = false;
633 UpdateIndex();
635 }
636
637 public void CopyTo(Array array, int index)
638 {
639 if (_index != null)
640 {
641 RBTree<int>.RBTreeEnumerator enumerator = _index.GetEnumerator(0);
642 while (enumerator.MoveNext())
643 {
644 array.SetValue(GetRowView(enumerator.Current), index);
645 index = checked(index + 1);
646 }
647 }
648 if (_addNewRow != null)
649 {
651 }
652 }
653
654 private void CopyTo(DataRowView[] array, int index)
655 {
656 if (_index != null)
657 {
658 RBTree<int>.RBTreeEnumerator enumerator = _index.GetEnumerator(0);
659 while (enumerator.MoveNext())
660 {
661 array[index] = GetRowView(enumerator.Current);
662 index = checked(index + 1);
663 }
664 }
665 if (_addNewRow != null)
666 {
668 }
669 }
670
671 public void Delete(int index)
672 {
674 }
675
676 internal void Delete(DataRow row)
677 {
678 if (row == null)
679 {
680 return;
681 }
682 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataView.Delete|API> {0}, row={1}", ObjectID, row._objectID);
683 try
684 {
685 CheckOpen();
686 if (row == _addNewRow)
687 {
688 FinishAddNew(success: false);
689 return;
690 }
691 if (!AllowDelete)
692 {
694 }
695 row.Delete();
696 }
697 finally
698 {
699 DataCommonEventSource.Log.ExitScope(scopeId);
700 }
701 }
702
703 protected override void Dispose(bool disposing)
704 {
705 if (disposing)
706 {
707 Close();
708 }
709 base.Dispose(disposing);
710 }
711
712 public int Find(object? key)
713 {
714 return FindByKey(key);
715 }
716
717 internal virtual int FindByKey(object key)
718 {
719 return _index.FindRecordByKey(key);
720 }
721
722 public int Find(object?[] key)
723 {
724 return FindByKey(key);
725 }
726
727 internal virtual int FindByKey(object[] key)
728 {
729 return _index.FindRecordByKey(key);
730 }
731
732 public DataRowView[] FindRows(object? key)
733 {
734 return FindRowsByKey(new object[1] { key });
735 }
736
737 public DataRowView[] FindRows(object?[] key)
738 {
739 return FindRowsByKey(key);
740 }
741
742 internal virtual DataRowView[] FindRowsByKey(object[] key)
743 {
744 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataView.FindRows|API> {0}", ObjectID);
745 try
746 {
749 }
750 finally
751 {
752 DataCommonEventSource.Log.ExitScope(scopeId);
753 }
754 }
755
756 internal Range FindRecords<TKey, TRow>(Index.ComparisonBySelector<TKey, TRow> comparison, TKey key) where TRow : DataRow?
757 {
759 }
760
762 {
763 if (range.IsNull)
764 {
765 return Array.Empty<DataRowView>();
766 }
768 for (int i = 0; i < array.Length; i++)
769 {
770 array[i] = this[i + range.Min];
771 }
772 return array;
773 }
774
775 internal void FinishAddNew(bool success)
776 {
777 DataCommonEventSource.Log.Trace("<ds.DataView.FinishAddNew|INFO> {0}, success={1}", ObjectID, success);
779 if (success)
780 {
781 if (DataRowState.Detached == addNewRow.RowState)
782 {
784 }
785 else
786 {
787 addNewRow.EndEdit();
788 }
789 }
790 if (addNewRow == _addNewRow)
791 {
792 bool flag = _rowViewCache.Remove(_addNewRow);
793 _addNewRow = null;
794 if (!success)
795 {
796 addNewRow.CancelEdit();
797 }
799 }
800 }
801
803 {
805 CopyTo(array, 0);
806 return array.GetEnumerator();
807 }
808
809 int IList.Add(object value)
810 {
811 if (value == null)
812 {
813 AddNew();
814 return Count - 1;
815 }
817 }
818
820 {
822 }
823
824 bool IList.Contains(object value)
825 {
826 return 0 <= IndexOf(value as DataRowView);
827 }
828
829 int IList.IndexOf(object value)
830 {
831 return IndexOf(value as DataRowView);
832 }
833
835 {
836 if (rowview != null)
837 {
838 if (_addNewRow == rowview.Row)
839 {
840 return Count - 1;
841 }
842 if (_index != null && DataRowState.Detached != rowview.Row.RowState && _rowViewCache.TryGetValue(rowview.Row, out var value) && value == rowview)
843 {
845 }
846 }
847 return -1;
848 }
849
851 {
852 return _index.GetIndex(rowview.Row.GetRecordFromVersion(rowview.Row.GetDefaultRowVersion(RowStateFilter) & (DataRowVersion)(-1025)));
853 }
854
855 void IList.Insert(int index, object value)
856 {
858 }
859
860 void IList.Remove(object value)
861 {
862 int num = IndexOf(value as DataRowView);
863 if (0 <= num)
864 {
865 ((IList)this).RemoveAt(num);
866 return;
867 }
869 }
870
872 {
873 Delete(index);
874 }
875
876 internal Index GetFindIndex(string column, bool keepIndex)
877 {
878 if (_findIndexes == null)
879 {
881 }
883 {
884 if (!keepIndex)
885 {
887 value.RemoveRef();
888 if (value.RefCount == 1)
889 {
890 value.RemoveRef();
891 }
892 }
893 }
894 else if (keepIndex)
895 {
898 value.AddRef();
899 }
900 return value;
901 }
902
904 {
905 return AddNew();
906 }
907
909 {
910 if (_table != null && _index != null && _index._indexFields.Length == 1)
911 {
913 }
914 return null;
915 }
916
921
926
928 {
929 if (property != null)
930 {
931 bool flag = false;
932 Index value = null;
933 try
934 {
935 if (_findIndexes == null || !_findIndexes.TryGetValue(property.Name, out value))
936 {
937 flag = true;
939 value.AddRef();
940 }
941 Range range = value.FindRecords(key);
942 if (!range.IsNull)
943 {
944 return _index.GetIndex(value.GetRecord(range.Min));
945 }
946 }
947 finally
948 {
949 if (flag && value != null)
950 {
951 value.RemoveRef();
952 if (value.RefCount == 1)
953 {
954 value.RemoveRef();
955 }
956 }
957 }
958 }
959 return -1;
960 }
961
966
968 {
969 DataCommonEventSource.Log.Trace("<ds.DataView.RemoveSort|API> {0}", ObjectID);
970 Sort = string.Empty;
971 }
972
974 {
975 if (sorts == null)
976 {
977 throw ExceptionBuilder.ArgumentNull("sorts");
978 }
980 bool flag = false;
982 {
983 if (item == null)
984 {
986 }
987 PropertyDescriptor propertyDescriptor = item.PropertyDescriptor;
988 if (propertyDescriptor == null)
989 {
990 throw ExceptionBuilder.ArgumentNull("PropertyDescriptor");
991 }
993 {
995 }
996 ListSortDirection sortDirection = item.SortDirection;
997 if (flag)
998 {
999 stringBuilder.Append(',');
1000 }
1002 if (!flag)
1003 {
1004 flag = true;
1005 }
1006 }
1007 Sort = stringBuilder.ToString();
1008 }
1009
1011 {
1013 stringBuilder.Append('[');
1014 stringBuilder.Append(property.Name);
1015 stringBuilder.Append(']');
1016 if (ListSortDirection.Descending == direction)
1017 {
1018 stringBuilder.Append(" DESC");
1019 }
1020 return stringBuilder.ToString();
1021 }
1022
1023 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Safe because filter is set to empty string.")]
1025 {
1026 DataCommonEventSource.Log.Trace("<ds.DataView.RemoveFilter|API> {0}", ObjectID);
1027 RowFilter = string.Empty;
1028 }
1029
1031 {
1033 if (_table != null && _index != null && _index._indexFields.Length != 0)
1034 {
1036 for (int i = 0; i < _index._indexFields.Length; i++)
1037 {
1040 {
1042 }
1043 else
1044 {
1046 }
1047 }
1048 }
1050 }
1051
1053 {
1054 if (_table != null)
1055 {
1056 if (listAccessors == null || listAccessors.Length == 0)
1057 {
1058 return _table.TableName;
1059 }
1061 if (dataSet != null)
1062 {
1064 if (dataTable != null)
1065 {
1066 return dataTable.TableName;
1067 }
1068 }
1069 }
1070 return string.Empty;
1071 }
1072
1074 {
1075 if (_table != null)
1076 {
1077 if (listAccessors == null || listAccessors.Length == 0)
1078 {
1080 }
1082 if (dataSet == null)
1083 {
1084 return new PropertyDescriptorCollection(null);
1085 }
1087 if (dataTable != null)
1088 {
1089 return dataTable.GetPropertyDescriptorCollection(null);
1090 }
1091 }
1092 return new PropertyDescriptorCollection(null);
1093 }
1094
1095 internal virtual IFilter GetFilter()
1096 {
1097 return _rowFilter;
1098 }
1099
1100 private int GetRecord(int recordIndex)
1101 {
1102 if ((uint)Count <= (uint)recordIndex)
1103 {
1105 }
1107 {
1109 }
1111 }
1112
1113 internal DataRow GetRow(int index)
1114 {
1115 int count = Count;
1116 if ((uint)count <= (uint)index)
1117 {
1119 }
1120 if (index == count - 1 && _addNewRow != null)
1121 {
1122 return _addNewRow;
1123 }
1125 }
1126
1128 {
1130 }
1131
1133 {
1134 return _rowViewCache[dr];
1135 }
1136
1137 protected virtual void IndexListChanged(object sender, ListChangedEventArgs e)
1138 {
1139 if (e.ListChangedType != 0)
1140 {
1141 OnListChanged(e);
1142 }
1143 if (_addNewRow != null && _index.RecordCount == 0)
1144 {
1145 FinishAddNew(success: false);
1146 }
1147 if (e.ListChangedType == ListChangedType.Reset)
1148 {
1149 OnListChanged(e);
1150 }
1151 }
1152
1164
1166 {
1167 DataRowView value = null;
1168 switch (changedType)
1169 {
1170 case ListChangedType.ItemAdded:
1172 {
1173 bool flag = _rowViewBuffer.Remove(row);
1174 }
1175 if (row == _addNewRow)
1176 {
1178 _addNewRow = null;
1180 }
1181 else if (!_rowViewCache.ContainsKey(row))
1182 {
1183 _rowViewCache.Add(row, value ?? new DataRowView(this, row));
1184 }
1185 break;
1186 case ListChangedType.ItemDeleted:
1187 if (trackAddRemove)
1188 {
1190 if (value != null)
1191 {
1193 }
1194 }
1196 break;
1197 case ListChangedType.Reset:
1199 break;
1200 case ListChangedType.ItemMoved:
1201 case ListChangedType.ItemChanged:
1202 case ListChangedType.PropertyDescriptorAdded:
1203 case ListChangedType.PropertyDescriptorDeleted:
1204 case ListChangedType.PropertyDescriptorChanged:
1205 break;
1206 }
1207 }
1208
1209 protected virtual void OnListChanged(ListChangedEventArgs e)
1210 {
1211 DataCommonEventSource.Log.Trace("<ds.DataView.OnListChanged|INFO> {0}, ListChangedType={1}", ObjectID, e.ListChangedType);
1212 try
1213 {
1214 DataColumn dataColumn = null;
1215 string text = null;
1216 switch (e.ListChangedType)
1217 {
1218 case ListChangedType.ItemMoved:
1219 case ListChangedType.ItemChanged:
1220 if (0 <= e.NewIndex)
1221 {
1223 if (row.HasPropertyChanged)
1224 {
1225 dataColumn = row.LastChangedColumn;
1226 text = ((dataColumn != null) ? dataColumn.ColumnName : string.Empty);
1227 }
1228 }
1229 break;
1230 }
1231 if (_onListChanged != null)
1232 {
1233 if (dataColumn != null && e.NewIndex == e.OldIndex)
1234 {
1236 _onListChanged(this, e2);
1237 }
1238 else
1239 {
1240 _onListChanged(this, e);
1241 }
1242 }
1243 if (text != null)
1244 {
1245 this[e.NewIndex].RaisePropertyChangedEvent(text);
1246 }
1247 }
1249 {
1251 }
1252 }
1253
1254 private void OnInitialized()
1255 {
1256 this.Initialized?.Invoke(this, EventArgs.Empty);
1257 }
1258
1259 protected void Open()
1260 {
1261 _shouldOpen = true;
1262 UpdateIndex();
1264 }
1265
1266 protected void Reset()
1267 {
1268 if (IsOpen)
1269 {
1270 _index.Reset();
1271 }
1272 }
1273
1274 internal void ResetRowViewCache()
1275 {
1278 if (_index != null)
1279 {
1280 RBTree<int>.RBTreeEnumerator enumerator = _index.GetEnumerator(0);
1281 while (enumerator.MoveNext())
1282 {
1285 {
1286 value = new DataRowView(this, dataRow);
1287 }
1288 dictionary.Add(dataRow, value);
1289 }
1290 }
1291 if (_addNewRow != null)
1292 {
1295 }
1297 }
1298
1300 {
1301 if (_table == null)
1302 {
1304 }
1306 {
1307 return;
1308 }
1309 if (dataViewManager != null)
1310 {
1311 dataViewManager._nViews--;
1312 }
1314 if (dataViewManager != null)
1315 {
1316 dataViewManager._nViews++;
1318 try
1319 {
1320 _applyDefaultSort = dataViewSetting.ApplyDefaultSort;
1323 }
1325 {
1327 }
1328 _locked = true;
1329 }
1330 else
1331 {
1332 SetIndex("", DataViewRowState.CurrentRows, null);
1333 }
1334 }
1335
1336 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "RowFilter is marked as unsafe because it can be used in DataExpression so that we only display warning when user is assigning an expression which means that in here we're either assigning empty filter which is safe or user has already seen a warning.")]
1341
1346
1348 {
1349 DataCommonEventSource.Log.Trace("<ds.DataView.SetIndex|INFO> {0}, newSort='{1}', newRowStates={2}", ObjectID, newSort, newRowStates);
1350 _sort = newSort;
1354 {
1355 return;
1356 }
1357 if (fireEvent)
1358 {
1359 UpdateIndex(force: true);
1360 }
1361 else
1362 {
1363 UpdateIndex(force: true, fireEvent: false);
1364 }
1365 if (_findIndexes == null)
1366 {
1367 return;
1368 }
1370 _findIndexes = null;
1372 {
1373 item.Value.RemoveRef();
1374 }
1375 }
1376
1377 protected void UpdateIndex()
1378 {
1379 UpdateIndex(force: false);
1380 }
1381
1382 protected virtual void UpdateIndex(bool force)
1383 {
1384 UpdateIndex(force, fireEvent: true);
1385 }
1386
1387 internal void UpdateIndex(bool force, bool fireEvent)
1388 {
1389 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataView.UpdateIndex|INFO> {0}, force={1}", ObjectID, force);
1390 try
1391 {
1392 if (!(_open != _shouldOpen || force))
1393 {
1394 return;
1395 }
1397 Index index = null;
1398 if (_open && _table != null)
1399 {
1400 if (SortComparison != null)
1401 {
1403 index.AddRef();
1404 }
1405 else
1406 {
1408 }
1409 }
1410 if (_index != index)
1411 {
1412 if (_index != null)
1413 {
1415 }
1416 _index = index;
1417 if (_index != null)
1418 {
1420 }
1422 if (fireEvent)
1423 {
1425 }
1426 }
1427 }
1428 finally
1429 {
1430 DataCommonEventSource.Log.ExitScope(scopeId);
1431 }
1432 }
1433
1435 {
1437 OnListChanged((e.Action == CollectionChangeAction.Add) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorAdded, new DataRelationPropertyDescriptor((DataRelation)e.Element)) : ((e.Action == CollectionChangeAction.Refresh) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorChanged, propDesc) : ((e.Action == CollectionChangeAction.Remove) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorDeleted, new DataRelationPropertyDescriptor((DataRelation)e.Element)) : null)));
1438 }
1439
1441 {
1443 OnListChanged((e.Action == CollectionChangeAction.Add) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorAdded, new DataRelationPropertyDescriptor((DataRelation)e.Element)) : ((e.Action == CollectionChangeAction.Refresh) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorChanged, propDesc) : ((e.Action == CollectionChangeAction.Remove) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorDeleted, new DataRelationPropertyDescriptor((DataRelation)e.Element)) : null)));
1444 }
1445
1446 protected virtual void ColumnCollectionChanged(object? sender, CollectionChangeEventArgs e)
1447 {
1449 OnListChanged((e.Action == CollectionChangeAction.Add) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorAdded, new DataColumnPropertyDescriptor((DataColumn)e.Element)) : ((e.Action == CollectionChangeAction.Refresh) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorChanged, propDesc) : ((e.Action == CollectionChangeAction.Remove) ? new ListChangedEventArgs(ListChangedType.PropertyDescriptorDeleted, new DataColumnPropertyDescriptor((DataColumn)e.Element)) : null)));
1450 }
1451
1453 {
1454 ColumnCollectionChanged(sender, e);
1455 }
1456
1458 {
1459 return ToTable(null, false);
1460 }
1461
1463 {
1464 return ToTable(tableName, false);
1465 }
1466
1468 {
1469 return ToTable(null, distinct, columnNames);
1470 }
1471
1472 public DataTable ToTable(string? tableName, bool distinct, params string[] columnNames)
1473 {
1474 DataCommonEventSource.Log.Trace("<ds.DataView.ToTable|API> {0}, TableName='{1}', distinct={2}", ObjectID, tableName, distinct);
1475 if (columnNames == null)
1476 {
1477 throw ExceptionBuilder.ArgumentNull("columnNames");
1478 }
1480 dataTable.Locale = _table.Locale;
1481 dataTable.CaseSensitive = _table.CaseSensitive;
1482 dataTable.TableName = ((tableName != null) ? tableName : _table.TableName);
1483 dataTable.Namespace = _table.Namespace;
1484 dataTable.Prefix = _table.Prefix;
1485 if (columnNames.Length == 0)
1486 {
1487 columnNames = new string[Table.Columns.Count];
1488 for (int i = 0; i < columnNames.Length; i++)
1489 {
1490 columnNames[i] = Table.Columns[i].ColumnName;
1491 }
1492 }
1493 int[] array = new int[columnNames.Length];
1495 for (int j = 0; j < columnNames.Length; j++)
1496 {
1498 if (dataColumn == null)
1499 {
1501 }
1502 dataTable.Columns.Add(dataColumn.Clone());
1504 }
1506 try
1507 {
1508 while (enumerator.MoveNext())
1509 {
1511 object[] array2 = new object[columnNames.Length];
1512 for (int k = 0; k < array.Length; k++)
1513 {
1514 array2[k] = dataRowView[array[k]];
1515 }
1516 if (!distinct || !RowExist(list, array2))
1517 {
1518 dataTable.Rows.Add(array2);
1519 list.Add(array2);
1520 }
1521 }
1522 return dataTable;
1523 }
1524 finally
1525 {
1527 if (disposable != null)
1528 {
1529 disposable.Dispose();
1530 }
1531 }
1532 }
1533
1534 private bool RowExist(List<object[]> arraylist, object[] objectArray)
1535 {
1536 for (int i = 0; i < arraylist.Count; i++)
1537 {
1538 object[] array = arraylist[i];
1539 bool flag = true;
1540 for (int j = 0; j < objectArray.Length; j++)
1541 {
1542 flag &= array[j].Equals(objectArray[j]);
1543 }
1544 if (flag)
1545 {
1546 return true;
1547 }
1548 }
1549 return false;
1550 }
1551
1552 public virtual bool Equals(DataView? view)
1553 {
1554 if (view == null || Table != view.Table || Count != view.Count || !string.Equals(RowFilter, view.RowFilter, StringComparison.OrdinalIgnoreCase) || !string.Equals(Sort, view.Sort, StringComparison.OrdinalIgnoreCase) || (object)SortComparison != view.SortComparison || (object)RowPredicate != view.RowPredicate || RowStateFilter != view.RowStateFilter || DataViewManager != view.DataViewManager || AllowDelete != view.AllowDelete || AllowNew != view.AllowNew || AllowEdit != view.AllowEdit)
1555 {
1556 return false;
1557 }
1558 return true;
1559 }
1560}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static bool IsCatchableExceptionType(Exception e)
Definition ADP.cs:790
static readonly DataCommonEventSource Log
PropertyDescriptorCollection GetPropertyDescriptorCollection(Attribute[] attributes)
DataRowCollection Rows
Definition DataTable.cs:701
DataColumnCollection Columns
Definition DataTable.cs:327
readonly List< DataView > _delayedViews
Definition DataTable.cs:188
IndexField[] ParseSortString(string sortString)
Index GetIndex(IndexField[] indexDesc)
string FormatSortString(IndexField[] indexDesc)
readonly RecordManager _recordManager
Definition DataTable.cs:74
IndexField[] _primaryIndex
Definition DataTable.cs:126
void RegisterListChangedEvent(Index index)
void RegisterMetaDataEvents(DataTable table)
bool Equals(DataRow x, DataRow y)
Definition DataView.cs:26
static readonly DataRowReferenceComparer s_default
Definition DataView.cs:20
readonly Predicate< DataRow > _predicateFilter
Definition DataView.cs:39
RowPredicateFilter(Predicate< DataRow > predicate)
Definition DataView.cs:41
int IndexOf(DataRowView rowview)
Definition DataView.cs:834
DataView(DataTable table, string? RowFilter, string? Sort, DataViewRowState RowState)
Definition DataView.cs:488
virtual void OnListChanged(ListChangedEventArgs e)
Definition DataView.cs:1209
DataTable ToTable()
Definition DataView.cs:1457
bool RowExist(List< object[]> arraylist, object[] objectArray)
Definition DataView.cs:1534
ListChangedEventArgs _addNewMoved
Definition DataView.cs:84
virtual void IndexListChanged(object sender, ListChangedEventArgs e)
Definition DataView.cs:1137
DataViewRowState _recordStates
Definition DataView.cs:68
bool IBindingList. AllowEdit
Definition DataView.cs:402
string _delayedRowFilter
Definition DataView.cs:92
DataView(DataTable table, Predicate< DataRow > predicate, Comparison< DataRow > comparison, DataViewRowState RowState)
Definition DataView.cs:520
DataView(DataTable table, bool locked)
Definition DataView.cs:465
Index GetFindIndex(string column, bool keepIndex)
Definition DataView.cs:876
override void Dispose(bool disposing)
Definition DataView.cs:703
void ChildRelationCollectionChanged(object sender, CollectionChangeEventArgs e)
Definition DataView.cs:1434
ListChangedEventHandler? ListChanged
Definition DataView.cs:450
DataViewRowState _delayedRecordStates
Definition DataView.cs:96
Dictionary< string, Index > _findIndexes
Definition DataView.cs:60
static int s_objectTypeCount
Definition DataView.cs:108
int GetRecord(int recordIndex)
Definition DataView.cs:1100
DataTable ToTable(bool distinct, params string[] columnNames)
Definition DataView.cs:1467
string CreateSortString(PropertyDescriptor property, ListSortDirection direction)
Definition DataView.cs:1010
readonly DataViewListener _dvListener
Definition DataView.cs:106
virtual ? string RowFilter
Definition DataView.cs:202
DataRowView[] FindRows(object? key)
Definition DataView.cs:732
DataRowView GetRowView(DataRow dr)
Definition DataView.cs:1132
Predicate< DataRow >? RowPredicate
Definition DataView.cs:234
void Delete(DataRow row)
Definition DataView.cs:676
Dictionary< DataRow, DataRowView > _rowViewCache
Definition DataView.cs:102
DataTable _delayedTable
Definition DataView.cs:90
DataRowView GetRowView(int record)
Definition DataView.cs:1127
virtual bool Equals(DataView? view)
Definition DataView.cs:1552
readonly int _objectID
Definition DataView.cs:110
bool IBindingList. AllowNew
Definition DataView.cs:400
void CopyTo(Array array, int index)
Definition DataView.cs:637
EventHandler? Initialized
Definition DataView.cs:463
static ListChangedEventArgs s_resetEventArgs
Definition DataView.cs:88
void ColumnCollectionChangedInternal(object sender, CollectionChangeEventArgs e)
Definition DataView.cs:1452
void CheckSort(string sort)
Definition DataView.cs:618
void MaintainDataView(ListChangedType changedType, DataRow row, bool trackAddRemove)
Definition DataView.cs:1165
void SetIndex2(string newSort, DataViewRowState newRowStates, IFilter newRowFilter, bool fireEvent)
Definition DataView.cs:1347
Comparison< DataRow > _comparison
Definition DataView.cs:64
DataViewRowState RowStateFilter
Definition DataView.cs:254
void IndexListChangedInternal(ListChangedEventArgs e)
Definition DataView.cs:1153
virtual void ColumnCollectionChanged(object? sender, CollectionChangeEventArgs e)
Definition DataView.cs:1446
int IndexOfDataRowView(DataRowView rowview)
Definition DataView.cs:850
DataRowView[] FindRows(object?[] key)
Definition DataView.cs:737
DataExpression CreateDataExpressionFromDataViewSettings(DataViewSetting dataViewSetting)
Definition DataView.cs:1337
virtual void SetIndex(string newSort, DataViewRowState newRowStates, IFilter newRowFilter)
Definition DataView.cs:1342
Comparison< DataRow >? SortComparison
Definition DataView.cs:317
PropertyDescriptor GetSortProperty()
Definition DataView.cs:908
Range FindRecords< TKey, TRow >(Index.ComparisonBySelector< TKey, TRow > comparison, TKey key)
Definition DataView.cs:756
DataTable ToTable(string? tableName)
Definition DataView.cs:1462
DataViewManager _dataViewManager
Definition DataView.cs:52
void Delete(int index)
Definition DataView.cs:671
ListSortDescriptionCollection GetSortDescriptions()
Definition DataView.cs:1030
virtual int FindByKey(object key)
Definition DataView.cs:717
readonly Dictionary< DataRow, DataRowView > _rowViewBuffer
Definition DataView.cs:104
void ParentRelationCollectionChanged(object sender, CollectionChangeEventArgs e)
Definition DataView.cs:1440
int Find(object? key)
Definition DataView.cs:712
virtual int FindByKey(object[] key)
Definition DataView.cs:727
void SetDataViewManager(DataViewManager dataViewManager)
Definition DataView.cs:1299
int IList. IndexOf(object value)
Definition DataView.cs:829
int Find(object?[] key)
Definition DataView.cs:722
DataTable ToTable(string? tableName, bool distinct, params string[] columnNames)
Definition DataView.cs:1472
DataView(DataTable? table)
Definition DataView.cs:481
virtual void UpdateIndex(bool force)
Definition DataView.cs:1382
virtual DataRowView[] FindRowsByKey(object[] key)
Definition DataView.cs:742
DataRow GetRow(int index)
Definition DataView.cs:1113
ListChangedEventHandler _onListChanged
Definition DataView.cs:86
virtual DataRowView AddNew()
Definition DataView.cs:544
void CopyTo(DataRowView[] array, int index)
Definition DataView.cs:654
virtual IFilter GetFilter()
Definition DataView.cs:1095
DataRowView[] GetDataRowViewFromRange(Range range)
Definition DataView.cs:761
void FinishAddNew(bool success)
Definition DataView.cs:775
IEnumerator GetEnumerator()
Definition DataView.cs:802
DataViewManager? DataViewManager
Definition DataView.cs:190
void UpdateIndex(bool force, bool fireEvent)
Definition DataView.cs:1387
static Exception CanNotSetTable()
static Exception GetElementIndex(int index)
static Exception AddExternalObject()
static Exception ColumnNotInTheUnderlyingTable(string column, string table)
static Exception RemoveExternalObject()
static Exception CanNotBindTable()
static Exception AddNewNotAllowNull()
static Exception ArgumentContainsNull(string paramName)
static Exception ColumnToSortIsOutOfRange(string column)
static Exception SetRowStateFilter()
static Exception InsertExternalObject()
static Exception TraceExceptionWithoutRethrow(Exception e)
static Exception RecordStateRange()
static Exception SetIListObject()
static Exception ArgumentNull(string paramName)
void AddRef()
Definition Index.cs:196
int GetIndex(int record)
Definition Index.cs:371
RBTree< int >.RBTreeEnumerator GetEnumerator(int startIndex)
Definition Index.cs:366
readonly IndexField[] _indexFields
Definition Index.cs:34
int FindRecordByKey(object key)
Definition Index.cs:429
int GetRecord(int recordIndex)
Definition Index.cs:148
Range FindRecords(object key)
Definition Index.cs:565
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
static readonly EventArgs Empty
Definition EventArgs.cs:9
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static CultureInfo CurrentCulture
static int Increment(ref int location)
void Insert(int index, T item)
void ApplySort(ListSortDescriptionCollection sorts)
void AddIndex(PropertyDescriptor property)
void ApplySort(PropertyDescriptor property, ListSortDirection direction)
void RemoveIndex(PropertyDescriptor property)
int Find(PropertyDescriptor property, object key)
PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
string GetListName(PropertyDescriptor[] listAccessors)
bool Invoke(DataRow row, DataRowVersion version)
delegate void ListChangedEventHandler(object? sender, ListChangedEventArgs e)
readonly bool IsDescending
Definition IndexField.cs:9
readonly DataColumn Column
Definition IndexField.cs:7