Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataColumn.cs
Go to the documentation of this file.
13using System.Xml;
15
16namespace System.Data;
17
18[ToolboxItem(false)]
19[DesignTimeVisible(false)]
20[DefaultProperty("ColumnName")]
21[Editor("Microsoft.VSDesigner.Data.Design.DataColumnEditor, 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")]
22[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
24{
25 private bool _allowNull = true;
26
27 private string _caption;
28
29 private string _columnName;
30
32 private Type _dataType;
33
35
36 internal object _defaultValue = DBNull.Value;
37
38 private DataSetDateTime _dateTimeMode = DataSetDateTime.UnspecifiedLocal;
39
41
42 private int _maxLength = -1;
43
44 private int _ordinal = -1;
45
46 private bool _readOnly;
47
48 internal Index _sortIndex;
49
50 internal DataTable _table;
51
52 private bool _unique;
53
55
56 internal int _hashCode;
57
58 internal int _errors;
59
60 private bool _isSqlType;
61
63
65
67
69
70 private bool _defaultValueIsNull = true;
71
73
75
77
79
80 internal string _columnUri;
81
82 private string _columnPrefix = string.Empty;
83
84 internal string _encodedColumnName;
85
87
88 private static int s_objectTypeCount;
89
91
92 [DefaultValue(true)]
93 public bool AllowDBNull
94 {
95 get
96 {
97 return _allowNull;
98 }
99 set
100 {
101 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataColumn.set_AllowDBNull|API> {0}, {1}", ObjectID, value);
102 try
103 {
104 if (_allowNull != value)
105 {
106 if (_table != null && !value && _table.EnforceConstraints)
107 {
109 }
111 }
112 }
113 finally
114 {
115 DataCommonEventSource.Log.ExitScope(scopeId);
116 }
117 }
118 }
119
120 [DefaultValue(false)]
122 public bool AutoIncrement
123 {
124 get
125 {
126 if (_autoInc != null)
127 {
128 return _autoInc.Auto;
129 }
130 return false;
131 }
132 set
133 {
134 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_AutoIncrement|API> {0}, {1}", ObjectID, value);
135 if (AutoIncrement == value)
136 {
137 return;
138 }
139 if (value)
140 {
141 if (_expression != null)
142 {
144 }
146 {
148 }
150 {
151 if (HasData)
152 {
154 }
155 DataType = typeof(int);
156 }
157 }
159 }
160 }
161
162 internal object AutoIncrementCurrent
163 {
164 get
165 {
166 if (_autoInc == null)
167 {
168 return AutoIncrementSeed;
169 }
170 return _autoInc.Current;
171 }
172 set
173 {
175 {
177 }
178 }
179 }
180
182
183 [DefaultValue(0L)]
185 {
186 get
187 {
188 if (_autoInc == null)
189 {
190 return 0L;
191 }
192 return _autoInc.Seed;
193 }
194 set
195 {
196 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_AutoIncrementSeed|API> {0}, {1}", ObjectID, value);
198 {
200 }
201 }
202 }
203
204 [DefaultValue(1L)]
206 {
207 get
208 {
209 if (_autoInc == null)
210 {
211 return 1L;
212 }
213 return _autoInc.Step;
214 }
215 set
216 {
217 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_AutoIncrementStep|API> {0}, {1}", ObjectID, value);
219 {
221 }
222 }
223 }
224
225 public string Caption
226 {
227 get
228 {
229 if (_caption == null)
230 {
231 return _columnName;
232 }
233 return _caption;
234 }
236 set
237 {
238 if (value == null)
239 {
240 value = string.Empty;
241 }
242 if (_caption == null || string.Compare(_caption, value, ignoreCase: true, Locale) != 0)
243 {
244 _caption = value;
245 }
246 }
247 }
248
250 [DefaultValue("")]
251 public string ColumnName
252 {
253 get
254 {
255 return _columnName;
256 }
258 set
259 {
260 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataColumn.set_ColumnName|API> {0}, '{1}'", ObjectID, value);
261 try
262 {
263 if (value == null)
264 {
265 value = string.Empty;
266 }
267 if (string.Compare(_columnName, value, ignoreCase: true, Locale) != 0)
268 {
269 if (_table != null)
270 {
271 if (value.Length == 0)
272 {
274 }
276 if (_columnName.Length != 0)
277 {
279 }
280 }
281 RaisePropertyChanging("ColumnName");
283 _encodedColumnName = null;
284 if (_table != null)
285 {
287 }
288 }
289 else if (_columnName != value)
290 {
291 RaisePropertyChanging("ColumnName");
293 _encodedColumnName = null;
294 if (_table != null)
295 {
297 }
298 }
299 }
300 finally
301 {
302 DataCommonEventSource.Log.ExitScope(scopeId);
303 }
304 }
305 }
306
307 internal string EncodedColumnName
308 {
309 get
310 {
311 if (_encodedColumnName == null)
312 {
314 }
315 return _encodedColumnName;
316 }
317 }
318
320 {
321 get
322 {
323 if (_table == null)
324 {
326 }
327 return _table.FormatProvider;
328 }
329 }
330
332 {
333 get
334 {
335 if (_table == null)
336 {
338 }
339 return _table.Locale;
340 }
341 }
342
343 internal int ObjectID => _objectID;
344
345 [DefaultValue("")]
346 public string Prefix
347 {
348 get
349 {
350 return _columnPrefix;
351 }
353 set
354 {
355 if (value == null)
356 {
357 value = string.Empty;
358 }
359 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_Prefix|API> {0}, '{1}'", ObjectID, value);
361 {
363 }
365 }
366 }
367
368 internal bool Computed => _expression != null;
369
371
372 [DefaultValue(typeof(string))]
377 {
378 get
379 {
380 return _dataType;
381 }
383 set
384 {
385 if (!(_dataType != value))
386 {
387 return;
388 }
389 if (HasData)
390 {
392 }
393 if (value == null)
394 {
396 }
399 {
401 }
402 if (_table != null && IsInRelation())
403 {
405 }
406 if (storageType == StorageType.BigInteger && _expression != null)
407 {
409 }
411 {
412 try
413 {
415 {
417 }
418 else if (typeof(BigInteger) == value)
419 {
421 }
422 else if (typeof(string) == value)
423 {
424 _defaultValue = DefaultValue.ToString();
425 }
426 else if (typeof(SqlString) == value)
427 {
429 }
430 else if (typeof(object) != value)
431 {
433 }
434 }
435 catch (InvalidCastException inner)
436 {
438 }
439 catch (FormatException inner2)
440 {
442 }
443 }
444 if (ColumnMapping == MappingType.SimpleContent && value == typeof(char))
445 {
447 }
449 if (StorageType.String == storageType)
450 {
451 _maxLength = -1;
452 }
454 XmlDataType = null;
455 if (!AutoIncrement)
456 {
457 return;
458 }
460 {
461 AutoIncrement = false;
462 }
463 if (_autoInc != null)
464 {
466 _autoInc = null;
467 AutoInc.Auto = autoInc.Auto;
468 AutoInc.Seed = autoInc.Seed;
469 AutoInc.Step = autoInc.Step;
470 if (_autoInc.DataType == autoInc.DataType)
471 {
472 _autoInc.Current = autoInc.Current;
473 }
474 else if (autoInc.DataType == typeof(long))
475 {
476 AutoInc.Current = (BigInteger)(long)autoInc.Current;
477 }
478 else
479 {
480 AutoInc.Current = (long)(BigInteger)autoInc.Current;
481 }
482 }
483 }
484 }
485
486 [DefaultValue(DataSetDateTime.UnspecifiedLocal)]
489 {
490 get
491 {
492 return _dateTimeMode;
493 }
494 set
495 {
496 if (_dateTimeMode == value)
497 {
498 return;
499 }
500 if (DataType != typeof(DateTime) && value != DataSetDateTime.UnspecifiedLocal)
501 {
503 }
504 switch (value)
505 {
506 case DataSetDateTime.Local:
507 case DataSetDateTime.Utc:
508 if (HasData)
509 {
511 }
512 break;
513 case DataSetDateTime.Unspecified:
514 case DataSetDateTime.UnspecifiedLocal:
515 if (_dateTimeMode != DataSetDateTime.Unspecified && _dateTimeMode != DataSetDateTime.UnspecifiedLocal && HasData)
516 {
518 }
519 break;
520 default:
522 }
524 }
525 }
526
528 public object DefaultValue
529 {
530 get
531 {
533 {
534 if (_storage != null)
535 {
537 }
538 else if (_isSqlType)
539 {
541 }
542 else if (_implementsINullable)
543 {
544 PropertyInfo property = _dataType.GetProperty("Null", BindingFlags.Static | BindingFlags.Public);
545 if (property != null)
546 {
547 _defaultValue = property.GetValue(null, null);
548 }
549 }
550 }
551 return _defaultValue;
552 }
554 set
555 {
556 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_DefaultValue|API> {0}", ObjectID);
557 if (_defaultValue != null && DefaultValue.Equals(value))
558 {
559 return;
560 }
561 if (AutoIncrement)
562 {
564 }
565 object obj = ((value == null) ? DBNull.Value : value);
566 if (obj != DBNull.Value && DataType != typeof(object))
567 {
568 try
569 {
571 }
572 catch (InvalidCastException inner)
573 {
575 }
576 }
579 }
580 }
581
583
585 [DefaultValue("")]
586 public string Expression
587 {
588 get
589 {
590 if (_expression != null)
591 {
592 return _expression.Expression;
593 }
594 return "";
595 }
596 [RequiresUnreferencedCode("Members from types used in the expressions may be trimmed if not referenced directly.")]
598 set
599 {
600 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataColumn.set_Expression|API> {0}, '{1}'", ObjectID, value);
601 if (value == null)
602 {
603 value = string.Empty;
604 }
605 try
606 {
608 if (value.Length > 0)
609 {
611 if (dataExpression2.HasValue)
612 {
614 }
615 }
616 if (_expression == null && dataExpression != null)
617 {
618 if (AutoIncrement || Unique)
619 {
621 }
622 if (_table != null)
623 {
624 for (int i = 0; i < _table.Constraints.Count; i++)
625 {
626 if (_table.Constraints[i].ContainsColumn(this))
627 {
629 }
630 }
631 }
632 bool readOnly = ReadOnly;
633 try
634 {
635 ReadOnly = true;
636 }
637 catch (ReadOnlyException e)
638 {
642 }
643 }
644 if (_table != null)
645 {
646 if (dataExpression != null && dataExpression.DependsOn(this))
647 {
649 }
653 try
654 {
655 if (dataExpression == null)
656 {
657 for (int j = 0; j < _table.RecordCapacity; j++)
658 {
660 }
661 }
662 else
663 {
665 }
668 return;
669 }
671 {
673 try
674 {
677 if (expression == null)
678 {
679 for (int k = 0; k < _table.RecordCapacity; k++)
680 {
682 }
683 }
684 else
685 {
687 }
690 }
692 {
694 }
695 throw;
696 }
697 }
699 }
700 finally
701 {
702 DataCommonEventSource.Log.ExitScope(scopeId);
703 }
704 }
705 }
706
707 [Browsable(false)]
709
710 internal bool HasData => _storage != null;
711
713
715
717
719
720 internal bool IsSqlType => _isSqlType;
721
722 [DefaultValue(-1)]
723 public int MaxLength
724 {
725 get
726 {
727 return _maxLength;
728 }
729 set
730 {
731 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataColumn.set_MaxLength|API> {0}, {1}", ObjectID, value);
732 try
733 {
734 if (_maxLength != value)
735 {
736 if (ColumnMapping == MappingType.SimpleContent)
737 {
739 }
740 if (DataType != typeof(string) && DataType != typeof(SqlString))
741 {
743 }
744 int maxLength = _maxLength;
745 _maxLength = Math.Max(value, -1);
746 if ((maxLength < 0 || value < maxLength) && _table != null && _table.EnforceConstraints && !CheckMaxLength())
747 {
748 _maxLength = maxLength;
750 }
752 }
753 }
754 finally
755 {
756 DataCommonEventSource.Log.ExitScope(scopeId);
757 }
758 }
759 }
760
761 public string Namespace
762 {
763 get
764 {
765 if (_columnUri == null)
766 {
767 if (Table != null && _columnMapping != MappingType.Attribute)
768 {
769 return Table.Namespace;
770 }
771 return string.Empty;
772 }
773 return _columnUri;
774 }
776 set
777 {
778 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_Namespace|API> {0}, '{1}'", ObjectID, value);
779 if (_columnUri != value)
780 {
781 if (_columnMapping != MappingType.SimpleContent)
782 {
783 RaisePropertyChanging("Namespace");
785 }
786 else if (value != Namespace)
787 {
789 }
790 }
791 }
792 }
793
794 [Browsable(false)]
796 public int Ordinal => _ordinal;
797
798 [DefaultValue(false)]
799 public bool ReadOnly
800 {
801 get
802 {
803 return _readOnly;
804 }
805 set
806 {
807 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_ReadOnly|API> {0}, {1}", ObjectID, value);
808 if (_readOnly != value)
809 {
810 if (!value && _expression != null)
811 {
813 }
815 }
816 }
817 }
818
821 {
822 get
823 {
824 if (_sortIndex == null)
825 {
827 {
828 new IndexField(this, isDescending: false)
829 };
832 }
833 return _sortIndex;
834 }
835 }
836
837 [Browsable(false)]
840
841 internal object this[int record]
842 {
843 get
844 {
845 return _storage.Get(record);
846 }
847 set
848 {
849 try
850 {
852 }
853 catch (Exception ex)
854 {
857 }
859 {
861 }
862 if (Computed)
863 {
865 if (dataRow != null)
866 {
868 }
869 }
870 }
871 }
872
873 [DefaultValue(false)]
875 public bool Unique
876 {
877 get
878 {
879 return _unique;
880 }
881 set
882 {
883 long scopeId = DataCommonEventSource.Log.EnterScope("<ds.DataColumn.set_Unique|API> {0}, {1}", ObjectID, value);
884 try
885 {
886 if (_unique == value)
887 {
888 return;
889 }
890 if (value && _expression != null)
891 {
893 }
894 UniqueConstraint constraint = null;
895 if (_table != null)
896 {
897 if (value)
898 {
899 CheckUnique();
900 }
901 else
902 {
904 while (enumerator.MoveNext())
905 {
906 if (enumerator.Current is UniqueConstraint uniqueConstraint && uniqueConstraint.ColumnsReference.Length == 1 && uniqueConstraint.ColumnsReference[0] == this)
907 {
908 constraint = uniqueConstraint;
909 }
910 }
911 _table.Constraints.CanRemove(constraint, fThrowException: true);
912 }
913 }
914 _unique = value;
915 if (_table != null)
916 {
917 if (value)
918 {
921 }
922 else
923 {
924 _table.Constraints.Remove(constraint);
925 }
926 }
927 }
928 finally
929 {
930 DataCommonEventSource.Log.ExitScope(scopeId);
931 }
932 }
933 }
934
935 internal string? XmlDataType { get; set; } = string.Empty;
936
937
939 {
940 get
941 {
942 return _simpleType;
943 }
944 set
945 {
947 if (value != null && value.CanHaveMaxLength())
948 {
949 _maxLength = value.MaxLength;
950 }
951 }
952 }
953
954 [DefaultValue(MappingType.Element)]
956 {
957 get
958 {
959 return _columnMapping;
960 }
961 set
962 {
963 DataCommonEventSource.Log.Trace("<ds.DataColumn.set_ColumnMapping|API> {0}, {1}", ObjectID, value);
964 if (value == _columnMapping)
965 {
966 return;
967 }
968 if (value == MappingType.SimpleContent && _table != null)
969 {
970 int num = 0;
971 if (_columnMapping == MappingType.Element)
972 {
973 num = 1;
974 }
975 if (_dataType == typeof(char))
976 {
978 }
979 if (_table.XmlText != null && _table.XmlText != this)
980 {
982 }
983 if (_table.ElementColumnCount > num)
984 {
986 }
987 }
988 RaisePropertyChanging("ColumnMapping");
989 if (_table != null)
990 {
991 if (_columnMapping == MappingType.SimpleContent)
992 {
993 _table._xmlText = null;
994 }
995 if (value == MappingType.Element)
996 {
998 }
999 else if (_columnMapping == MappingType.Element)
1000 {
1002 }
1003 }
1005 if (value == MappingType.SimpleContent)
1006 {
1007 _columnUri = null;
1008 if (_table != null)
1009 {
1010 _table.XmlText = this;
1011 }
1012 SimpleType = null;
1013 }
1014 }
1015 }
1016
1017 internal bool IsCustomType
1018 {
1019 get
1020 {
1021 if (_storage == null)
1022 {
1024 }
1026 }
1027 }
1028
1030
1031 internal event PropertyChangedEventHandler? PropertyChanging;
1032
1033 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is safe because type is string and expression is null.")]
1034 public DataColumn()
1036 {
1037 }
1038
1039 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is safe because type is string and expression is null.")]
1040 public DataColumn(string? columnName)
1042 {
1043 }
1044
1045 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Expression is null and `dataType` is marked appropriately.")]
1047 : this(columnName, dataType, null, MappingType.Element)
1048 {
1049 }
1050
1051 [RequiresUnreferencedCode("Members from serialized types or types used in expressions may be trimmed if not referenced directly.")]
1052 public DataColumn(string? columnName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)] Type dataType, string? expr)
1053 : this(columnName, dataType, expr, MappingType.Element)
1054 {
1055 }
1056
1057 [RequiresUnreferencedCode("Members from serialized types or types used in expressions may be trimmed if not referenced directly.")]
1059 {
1060 GC.SuppressFinalize(this);
1061 DataCommonEventSource.Log.Trace("<ds.DataColumn.DataColumn|API> {0}, columnName='{1}', expr='{2}', type={3}", ObjectID, columnName, expr, type);
1062 if (dataType == null)
1063 {
1064 throw ExceptionBuilder.ArgumentNull("dataType");
1065 }
1068 {
1070 }
1071 _columnName = columnName ?? string.Empty;
1073 if (simpleType != null)
1074 {
1076 }
1077 UpdateColumnType(dataType, storageType);
1078 if (!string.IsNullOrEmpty(expr))
1079 {
1080 Expression = expr;
1081 }
1083 }
1084
1100
1101 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1103 {
1104 object value = this[row.GetRecordFromVersion(version)];
1106 {
1107 return null;
1108 }
1109 return ConvertObjectToXml(value);
1110 }
1111
1112 internal void BindExpression()
1113 {
1115 }
1116
1118 {
1119 if (_simpleType != null)
1120 {
1123 {
1124 _simpleType = null;
1125 }
1126 else if (_simpleType.Name != null && XmlDataType != null)
1127 {
1129 XmlDataType = null;
1130 }
1131 }
1132 else if (-1 < _maxLength)
1133 {
1135 }
1136 }
1137
1138 public void SetOrdinal(int ordinal)
1139 {
1140 if (_ordinal == -1)
1141 {
1143 }
1144 if (_ordinal != ordinal)
1145 {
1147 }
1148 }
1149
1150 internal void SetOrdinalInternal(int ordinal)
1151 {
1152 if (_ordinal == ordinal)
1153 {
1154 return;
1155 }
1156 if (Unique && _ordinal != -1 && ordinal == -1)
1157 {
1159 if (uniqueConstraint != null)
1160 {
1162 }
1163 }
1164 if (_sortIndex != null && -1 == ordinal)
1165 {
1168 _sortIndex = null;
1169 }
1170 int ordinal2 = _ordinal;
1171 _ordinal = ordinal;
1172 if (ordinal2 == -1 && _ordinal != -1 && Unique)
1173 {
1174 UniqueConstraint constraint = new UniqueConstraint(this);
1175 _table.Constraints.Add(constraint);
1176 }
1177 }
1178
1179 internal void SetTable(DataTable table)
1180 {
1181 if (_table == table)
1182 {
1183 return;
1184 }
1185 if (Computed && (table == null || (!table.fInitInProgress && (table.DataSet == null || (!table.DataSet._fIsSchemaLoading && !table.DataSet._fInitInProgress)))))
1186 {
1187 DataExpression.Bind(table);
1188 }
1189 if (Unique && _table != null)
1190 {
1192 if (uniqueConstraint != null)
1193 {
1195 }
1196 }
1197 _table = table;
1198 _storage = null;
1199 }
1200
1202 {
1203 return _table._recordManager[index];
1204 }
1205
1206 internal void InitializeRecord(int record)
1207 {
1209 }
1210
1211 internal void SetValue(int record, object value)
1212 {
1213 try
1214 {
1216 }
1217 catch (Exception ex)
1218 {
1221 }
1223 if (dataRow != null)
1224 {
1226 }
1227 }
1228
1229 internal void FreeRecord(int record)
1230 {
1232 }
1233
1234 internal void InternalUnique(bool value)
1235 {
1236 _unique = value;
1237 }
1238
1240 {
1242 {
1245 }
1246 }
1247
1248 internal bool CheckMaxLength()
1249 {
1250 if (0 <= _maxLength && Table != null && 0 < Table.Rows.Count)
1251 {
1252 foreach (DataRow row in Table.Rows)
1253 {
1254 if (row.HasVersion(DataRowVersion.Current) && _maxLength < GetStringLength(row.GetCurrentRecordNo()))
1255 {
1256 return false;
1257 }
1258 }
1259 }
1260 return true;
1261 }
1262
1264 {
1265 if (0 <= _maxLength && _maxLength < GetStringLength(dr.GetDefaultRecord()))
1266 {
1268 }
1269 }
1270
1271 protected internal void CheckNotAllowNull()
1272 {
1273 if (_storage == null)
1274 {
1275 return;
1276 }
1277 if (_sortIndex != null)
1278 {
1280 {
1281 return;
1282 }
1284 }
1285 foreach (DataRow row in _table.Rows)
1286 {
1287 if (row.RowState == DataRowState.Deleted)
1288 {
1289 continue;
1290 }
1292 {
1293 if (row[this] == DBNull.Value)
1294 {
1296 }
1297 }
1298 else if (DataStorage.IsObjectNull(row[this]))
1299 {
1301 }
1302 }
1303 }
1304
1306 {
1307 if (!AllowDBNull && _storage.IsNull(row.GetDefaultRecord()))
1308 {
1310 }
1311 }
1312
1313 protected void CheckUnique()
1314 {
1315 if (!SortIndex.CheckUnique())
1316 {
1318 }
1319 }
1320
1321 internal int Compare(int record1, int record2)
1322 {
1324 }
1325
1326 internal bool CompareValueTo(int record1, object value, bool checkType)
1327 {
1328 if (CompareValueTo(record1, value) == 0)
1329 {
1330 Type type = value.GetType();
1331 Type type2 = _storage.Get(record1).GetType();
1332 if (type == typeof(string) && type2 == typeof(string))
1333 {
1334 if (string.CompareOrdinal((string)_storage.Get(record1), (string)value) != 0)
1335 {
1336 return false;
1337 }
1338 return true;
1339 }
1340 if (type == type2)
1341 {
1342 return true;
1343 }
1344 }
1345 return false;
1346 }
1347
1348 internal int CompareValueTo(int record1, object value)
1349 {
1351 }
1352
1353 internal object ConvertValue(object value)
1354 {
1355 return _storage.ConvertValue(value);
1356 }
1357
1358 internal void Copy(int srcRecordNo, int dstRecordNo)
1359 {
1361 }
1362
1363 [MethodImpl(MethodImplOptions.NoInlining)]
1394
1395 internal object GetAggregateValue(int[] records, AggregateType kind)
1396 {
1397 if (_storage == null)
1398 {
1399 if (kind != AggregateType.Count)
1400 {
1401 return DBNull.Value;
1402 }
1403 return 0;
1404 }
1405 return _storage.Aggregate(records, kind);
1406 }
1407
1408 private int GetStringLength(int record)
1409 {
1411 }
1412
1413 internal void Init(int record)
1414 {
1415 if (AutoIncrement)
1416 {
1417 object current = _autoInc.Current;
1419 _storage.Set(record, current);
1420 }
1421 else
1422 {
1423 this[record] = _defaultValue;
1424 }
1425 }
1426
1427 internal static bool IsAutoIncrementType(Type dataType)
1428 {
1429 if (!(dataType == typeof(int)) && !(dataType == typeof(long)) && !(dataType == typeof(short)) && !(dataType == typeof(decimal)) && !(dataType == typeof(BigInteger)) && !(dataType == typeof(SqlInt32)) && !(dataType == typeof(SqlInt64)) && !(dataType == typeof(SqlInt16)))
1430 {
1431 return dataType == typeof(SqlDecimal);
1432 }
1433 return true;
1434 }
1435
1436 internal bool IsValueCustomTypeInstance(object value)
1437 {
1438 if (DataStorage.IsTypeCustomType(value.GetType()))
1439 {
1440 return !(value is Type);
1441 }
1442 return false;
1443 }
1444
1445 internal bool IsNull(int record)
1446 {
1447 return _storage.IsNull(record);
1448 }
1449
1450 internal bool IsInRelation()
1451 {
1453 for (int i = 0; i < parentRelations.Count; i++)
1454 {
1455 if (parentRelations[i].ChildKey.ContainsColumn(this))
1456 {
1457 return true;
1458 }
1459 }
1461 for (int j = 0; j < parentRelations.Count; j++)
1462 {
1463 if (parentRelations[j].ParentKey.ContainsColumn(this))
1464 {
1465 return true;
1466 }
1467 }
1468 return false;
1469 }
1470
1471 internal bool IsMaxLengthViolated()
1472 {
1473 if (MaxLength < 0)
1474 {
1475 return true;
1476 }
1477 bool result = false;
1478 string text = null;
1479 foreach (DataRow row in Table.Rows)
1480 {
1481 if (!row.HasVersion(DataRowVersion.Current))
1482 {
1483 continue;
1484 }
1485 object obj = row[this];
1486 if (!_isSqlType)
1487 {
1488 if (obj != null && obj != DBNull.Value && ((string)obj).Length > MaxLength)
1489 {
1490 if (text == null)
1491 {
1493 }
1495 row.SetColumnError(this, text);
1496 result = true;
1497 }
1498 }
1499 else if (!DataStorage.IsObjectNull(obj) && ((SqlString)obj).Value.Length > MaxLength)
1500 {
1501 if (text == null)
1502 {
1504 }
1506 row.SetColumnError(this, text);
1507 result = true;
1508 }
1509 }
1510 return result;
1511 }
1512
1514 {
1516 DataRow[] rows = sortIndex.GetRows(sortIndex.FindRecords(DBNull.Value));
1517 for (int i = 0; i < rows.Length; i++)
1518 {
1520 rows[i].RowError = text;
1521 rows[i].SetColumnError(this, text);
1522 }
1523 return rows.Length != 0;
1524 }
1525
1526 internal void FinishInitInProgress()
1527 {
1528 if (Computed)
1529 {
1531 }
1532 }
1533
1535 {
1536 this.PropertyChanging?.Invoke(this, pcevent);
1537 }
1538
1539 protected internal void RaisePropertyChanging(string name)
1540 {
1542 }
1543
1545 {
1546 if (_storage == null)
1547 {
1549 }
1550 return _storage;
1551 }
1552
1553 internal void SetCapacity(int capacity)
1554 {
1556 }
1557
1558 internal void OnSetDataSet()
1559 {
1560 }
1561
1562 public override string ToString()
1563 {
1564 if (_expression != null)
1565 {
1566 return ColumnName + " + " + Expression;
1567 }
1568 return ColumnName;
1569 }
1570
1571 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1572 internal object ConvertXmlToObject(string s)
1573 {
1575 }
1576
1577 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1582
1583 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1584 internal string ConvertObjectToXml(object value)
1585 {
1587 }
1588
1589 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1594
1596 {
1598 }
1599
1604
1605 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1606 internal void SetStorage(object store, BitArray nullbits)
1607 {
1609 }
1610
1620
1629
1631 {
1633 if (oldExpression != null)
1634 {
1635 dependency = oldExpression.GetDependency();
1637 foreach (DataColumn dataColumn in array)
1638 {
1639 dataColumn.RemoveDependentColumn(this);
1640 if (dataColumn._table != _table)
1641 {
1643 }
1644 }
1646 }
1647 if (newExpression == null)
1648 {
1649 return;
1650 }
1651 dependency = newExpression.GetDependency();
1653 foreach (DataColumn dataColumn2 in array2)
1654 {
1655 dataColumn2.AddDependentColumn(this);
1656 if (dataColumn2._table != _table)
1657 {
1659 }
1660 }
1662 }
1663
1664 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "User has already got warning when creating original column.")]
1666 {
1667 Expression = source.Expression;
1668 }
1669}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
virtual ICollection Keys
Definition Hashtable.cs:532
static readonly DBNull Value
Definition DBNull.cs:8
void SetCurrentAndIncrement(object value)
void SetCurrent(object value, IFormatProvider formatProvider)
static bool IsCatchableExceptionType(Exception e)
Definition ADP.cs:790
static object ConvertFromBigInteger(BigInteger value, Type type, IFormatProvider formatProvider)
static BigInteger ConvertToBigInteger(object value, IFormatProvider formatProvider)
object Get(int recordNo)
static bool IsObjectNull(object value)
void Set(int recordNo, object value)
static void ImplementsInterfaces(StorageType typeCode, Type dataType, out bool sqlType, out bool nullable, out bool xmlSerializable, out bool changeTracking, out bool revertibleChangeTracking)
virtual object ConvertValue(object value)
static bool ImplementsINullableValue(StorageType typeCode, Type dataType)
int CompareValueTo(int recordNo1, object value)
virtual void SetCapacity(int capacity)
static DataStorage CreateStorage(DataColumn column, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type dataType, StorageType typeCode)
void CopyValueInternal(int record, object store, BitArray nullbits, int storeIndex)
string ConvertObjectToXml(object value)
void SetStorageInternal(object store, BitArray nullbits)
virtual int GetStringLength(int record)
object ConvertXmlToObject(string s)
static bool IsTypeCustomType(Type type)
virtual object Aggregate(int[] recordNos, AggregateType kind)
virtual bool IsNull(int recordNo)
static bool IsObjectSqlNull(object value)
int Compare(int recordNo1, int recordNo2)
object GetEmptyStorageInternal(int recordCount)
static StorageType GetStorageType(Type dataType)
void Copy(int recordNo1, int recordNo2)
static object ChangeTypeForDefaultValue(object value, Type type, IFormatProvider formatProvider)
static SqlString ConvertToSqlString(object value)
static object GetStaticNullForUdtType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
UniqueConstraint FindKeyConstraint(DataColumn[] columns)
bool CanRemove(Constraint constraint)
void Remove(Constraint constraint)
void Add(Constraint constraint)
void MoveTo(DataColumn column, int newPosition)
void OnColumnPropertyChanged(CollectionChangeEventArgs ccevent)
void RegisterColumnName(string name, DataColumn column)
DataStorage InsureStorage()
DataSetDateTime _dateTimeMode
Definition DataColumn.cs:38
void Copy(int srcRecordNo, int dstRecordNo)
void ConvertObjectToXml(object value, XmlWriter xmlWriter, XmlRootAttribute xmlAttrib)
DataColumn(string? columnName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type dataType)
object ConvertXmlToObject(string s)
bool IsNull(int record)
void InternalUnique(bool value)
bool IsValueCustomTypeInstance(object value)
int CompareValueTo(int record1, object value)
DataRow GetDataRow(int index)
AutoIncrementValue _autoInc
Definition DataColumn.cs:78
void SetOrdinal(int ordinal)
object ConvertValue(object value)
DataColumn(string? columnName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type dataType, string? expr)
static bool IsAutoIncrementType(Type dataType)
override string ToString()
void SetTable(DataTable table)
string ConvertObjectToXml(object value)
DataColumn(string? columnName)
void SetOrdinalInternal(int ordinal)
void CheckColumnConstraint(DataRow row, DataRowAction action)
void AddDependentColumn(DataColumn expressionColumn)
readonly int _objectID
Definition DataColumn.cs:90
object GetEmptyColumnStore(int recordCount)
object ConvertXmlToObject(XmlReader xmlReader, XmlRootAttribute xmlAttrib)
object GetAggregateValue(int[] records, AggregateType kind)
void CheckNullable(DataRow row)
int Compare(int record1, int record2)
StorageType _storageType
Definition DataColumn.cs:34
virtual MappingType ColumnMapping
PropertyChangedEventHandler? PropertyChanging
void CheckMaxLength(DataRow dr)
void RemoveDependentColumn(DataColumn expressionColumn)
void UpdateColumnType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type type, StorageType typeCode)
DataColumn(string? columnName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type dataType, string? expr, MappingType type)
void InitializeRecord(int record)
bool ImplementsIRevertibleChangeTracking
bool _implementsIRevertibleChangeTracking
Definition DataColumn.cs:66
PropertyCollection ExtendedProperties
DataExpression _expression
Definition DataColumn.cs:40
void RaisePropertyChanging(string name)
void FreeRecord(int record)
AutoIncrementValue AutoInc
void Init(int record)
PropertyCollection _extendedProperties
Definition DataColumn.cs:74
void SetValue(int record, object value)
MappingType _columnMapping
Definition DataColumn.cs:54
void CopyValueIntoStore(int record, object store, BitArray nullbits, int storeIndex)
DataSetDateTime DateTimeMode
DataExpression? DataExpression
void CopyExpressionFrom(DataColumn source)
List< DataColumn > _dependentColumns
Definition DataColumn.cs:72
string GetColumnValueAsString(DataRow row, DataRowVersion version)
int GetStringLength(int record)
void HandleDependentColumnList(DataExpression oldExpression, DataExpression newExpression)
virtual void OnPropertyChanging(PropertyChangedEventArgs pcevent)
void SetCapacity(int capacity)
bool CompareValueTo(int record1, object value, bool checkType)
void SetStorage(object store, BitArray nullbits)
static int s_objectTypeCount
Definition DataColumn.cs:88
static readonly DataCommonEventSource Log
void Bind(DataTable table)
IFormatProvider FormatProvider
Definition DataTable.cs:435
DataRowCollection Rows
Definition DataTable.cs:701
DataColumn? XmlText
Definition DataTable.cs:855
void EvaluateDependentExpressions(DataColumn column)
void RemoveDependentColumn(DataColumn expressionColumn)
void AddDependentColumn(DataColumn expressionColumn)
ConstraintCollection Constraints
Definition DataTable.cs:332
void ResetInternalIndexes(DataColumn column)
DataColumnCollection Columns
Definition DataTable.cs:327
bool UpdatingCurrent(DataRow row, DataRowAction action)
DataRelationCollection ParentRelations
Definition DataTable.cs:572
Index GetIndex(IndexField[] indexDesc)
readonly RecordManager _recordManager
Definition DataTable.cs:74
DataRelationCollection ChildRelations
Definition DataTable.cs:324
static Exception CantChangeDateTimeMode(DataSetDateTime oldValue, DataSetDateTime newValue)
static Exception DefaultValueDataType(string column, Type defaultType, Type columnType, Exception inner)
static string MaxLengthViolationText(string columnName)
static Exception ColumnTypeNotSupported()
static Exception CannotSetSimpleContentType(string columnName, Type type)
static Exception ExpressionCircular()
static Exception AutoIncrementAndExpression()
static Exception ColumnsTypeMismatch()
static Exception ReadOnlyAndExpression()
static Exception ExpressionAndConstraint(DataColumn column, Constraint constraint)
static Exception CannotSetMaxLength(DataColumn column, int value)
static Exception DefaultValueColumnDataType(string column, Type defaultType, Type columnType, Exception inner)
static Exception NonUniqueValues(string column)
static Exception DefaultValueAndAutoIncrement()
static Exception CantChangeDataType()
static Exception NullKeyValues(string column)
static string NotAllowDBNullViolationText(string columnName)
static Exception HasToBeStringType(DataColumn column)
static Exception AutoIncrementAndDefaultValue()
static Exception LongerThanMaxLength(DataColumn column)
static Exception NullValues(string column)
static Exception CannotSetMaxLength2(DataColumn column)
static Exception CannotSetSimpleContent(string columnName, Type type)
static Exception SetFailed(object value, DataColumn column, Type type, Exception innerException)
static Exception ColumnNotInAnyTable()
static Exception CannotAddColumn3()
static Exception AutoIncrementCannotSetIfHasData(string typeName)
static Exception ExpressionAndReadOnly()
static Exception ColumnNameRequired()
static Exception InvalidPrefix(string name)
static Exception CannotSetDateTimeModeForNonDateTimeColumns()
static Exception TraceExceptionForCapture(Exception e)
static Exception ExpressionAndUnique()
static Exception CannotAddColumn4(string column)
static Exception UniqueAndExpression()
static Exception TraceExceptionWithoutRethrow(Exception e)
static Exception CannotChangeNamespace(string columnName)
static Exception InvalidDateTimeMode(DataSetDateTime mode)
static Exception ArgumentNull(string paramName)
static Exception UnsupportedDataType(Type type)
void AddRef()
Definition Index.cs:196
bool CheckUnique()
Definition Index.cs:259
bool IsKeyInIndex(object key)
Definition Index.cs:713
int RemoveRef()
Definition Index.cs:215
static SimpleType CreateLimitedStringType(int length)
void ConvertToAnnonymousSimpleType()
static SimpleType CreateSimpleType(StorageType typeCode, Type type)
static void EnsureTypeIsAllowed(Type type, TypeLimiter capturedLimiter=null)
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static CultureInfo CurrentCulture
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static int Increment(ref int location)
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
PropertyInfo? GetProperty(string name)
Definition Type.cs:815
static ? string EncodeName(string? name)
Definition XmlConvert.cs:37
static ? string DecodeName(string? name)
Definition XmlConvert.cs:55
static ? string EncodeLocalName(string? name)
Definition XmlConvert.cs:49