Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataStorage.cs
Go to the documentation of this file.
7using System.Xml;
9
10namespace System.Data.Common;
11
12internal abstract class DataStorage
13{
14 private static readonly Type[] s_storageClassType = new Type[41]
15 {
16 null,
17 typeof(object),
19 typeof(bool),
20 typeof(char),
21 typeof(sbyte),
22 typeof(byte),
23 typeof(short),
24 typeof(ushort),
25 typeof(int),
26 typeof(uint),
27 typeof(long),
28 typeof(ulong),
29 typeof(float),
30 typeof(double),
31 typeof(decimal),
34 typeof(string),
35 typeof(Guid),
36 typeof(byte[]),
37 typeof(char[]),
38 typeof(Type),
41 typeof(Uri),
57 };
58
59 internal readonly DataColumn _column;
60
61 internal readonly DataTable _table;
62
63 internal readonly Type _dataType;
64
65 internal readonly StorageType _storageTypeCode;
66
68
69 private readonly object _defaultValue;
70
71 internal readonly object _nullValue;
72
73 internal readonly bool _isCloneable;
74
75 internal readonly bool _isCustomDefinedType;
76
77 internal readonly bool _isStringType;
78
79 internal readonly bool _isValueType;
80
82
84
86
88
93
98
112
113 public virtual object Aggregate(int[] recordNos, AggregateType kind)
114 {
115 if (AggregateType.Count == kind)
116 {
118 }
119 return null;
120 }
121
122 public object AggregateCount(int[] recordNos)
123 {
124 int num = 0;
125 for (int i = 0; i < recordNos.Length; i++)
126 {
127 if (!_dbNullBits.Get(recordNos[i]))
128 {
129 num++;
130 }
131 }
132 return num;
133 }
134
135 protected int CompareBits(int recordNo1, int recordNo2)
136 {
137 bool flag = _dbNullBits.Get(recordNo1);
139 if (flag ^ flag2)
140 {
141 if (flag)
142 {
143 return -1;
144 }
145 return 1;
146 }
147 return 0;
148 }
149
150 public abstract int Compare(int recordNo1, int recordNo2);
151
152 public abstract int CompareValueTo(int recordNo1, object value);
153
154 public virtual object ConvertValue(object value)
155 {
156 return value;
157 }
158
163
164 public abstract void Copy(int recordNo1, int recordNo2);
165
166 public abstract object Get(int recordNo);
167
168 protected object GetBits(int recordNo)
169 {
171 {
172 return _nullValue;
173 }
174 return _defaultValue;
175 }
176
177 public virtual int GetStringLength(int record)
178 {
179 return int.MaxValue;
180 }
181
182 protected bool HasValue(int recordNo)
183 {
184 return !_dbNullBits.Get(recordNo);
185 }
186
187 public virtual bool IsNull(int recordNo)
188 {
189 return _dbNullBits.Get(recordNo);
190 }
191
192 public abstract void Set(int recordNo, object value);
193
194 protected void SetNullBit(int recordNo, bool flag)
195 {
196 _dbNullBits.Set(recordNo, flag);
197 }
198
199 public virtual void SetCapacity(int capacity)
200 {
201 if (_dbNullBits == null)
202 {
204 }
205 else
206 {
208 }
209 }
210
211 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
212 public abstract object ConvertXmlToObject(string s);
213
214 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
216 {
217 return ConvertXmlToObject(xmlReader.Value);
218 }
219
220 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
221 public abstract string ConvertObjectToXml(object value);
222
223 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
225 {
226 xmlWriter.WriteString(ConvertObjectToXml(value));
227 }
228
230 {
231 if (typeCode == StorageType.Empty && null != dataType)
232 {
233 if (typeof(INullable).IsAssignableFrom(dataType))
234 {
235 return new SqlUdtStorage(column, dataType);
236 }
237 return new ObjectStorage(column, dataType);
238 }
239 return typeCode switch
240 {
259 StorageType.Guid => new ObjectStorage(column, dataType),
260 StorageType.ByteArray => new ObjectStorage(column, dataType),
261 StorageType.CharArray => new ObjectStorage(column, dataType),
262 StorageType.Type => new ObjectStorage(column, dataType),
265 StorageType.Uri => new ObjectStorage(column, dataType),
281 _ => new ObjectStorage(column, dataType),
282 };
283 }
284
285 internal static StorageType GetStorageType(Type dataType)
286 {
287 for (int i = 0; i < s_storageClassType.Length; i++)
288 {
289 if (dataType == s_storageClassType[i])
290 {
291 return (StorageType)i;
292 }
293 }
294 TypeCode typeCode = Type.GetTypeCode(dataType);
295 if (TypeCode.Object != typeCode)
296 {
297 return (StorageType)typeCode;
298 }
299 return StorageType.Empty;
300 }
301
303 {
304 return s_storageClassType[(int)storageType];
305 }
306
307 internal static bool IsTypeCustomType(Type type)
308 {
310 }
311
312 internal static bool IsTypeCustomType(StorageType typeCode)
313 {
314 if (StorageType.Object != typeCode && typeCode != 0)
315 {
316 return StorageType.CharArray == typeCode;
317 }
318 return true;
319 }
320
321 internal static bool IsSqlType(StorageType storageType)
322 {
324 }
325
326 public static bool IsSqlType(Type dataType)
327 {
328 for (int i = 26; i < s_storageClassType.Length; i++)
329 {
330 if (dataType == s_storageClassType[i])
331 {
332 return true;
333 }
334 }
335 return false;
336 }
337
338 private static bool DetermineIfValueType(StorageType typeCode, Type dataType)
339 {
340 switch (typeCode)
341 {
342 case StorageType.Boolean:
343 case StorageType.Char:
344 case StorageType.SByte:
345 case StorageType.Byte:
346 case StorageType.Int16:
347 case StorageType.UInt16:
348 case StorageType.Int32:
349 case StorageType.UInt32:
350 case StorageType.Int64:
351 case StorageType.UInt64:
352 case StorageType.Single:
353 case StorageType.Double:
354 case StorageType.Decimal:
355 case StorageType.DateTime:
356 case StorageType.TimeSpan:
357 case StorageType.Guid:
358 case StorageType.DateTimeOffset:
359 case StorageType.BigInteger:
360 case StorageType.SqlBinary:
361 case StorageType.SqlBoolean:
362 case StorageType.SqlByte:
363 case StorageType.SqlDateTime:
364 case StorageType.SqlDecimal:
365 case StorageType.SqlDouble:
366 case StorageType.SqlGuid:
367 case StorageType.SqlInt16:
368 case StorageType.SqlInt32:
369 case StorageType.SqlInt64:
370 case StorageType.SqlMoney:
371 case StorageType.SqlSingle:
372 case StorageType.SqlString:
373 return true;
374 case StorageType.String:
375 case StorageType.ByteArray:
376 case StorageType.CharArray:
377 case StorageType.Type:
378 case StorageType.Uri:
379 case StorageType.SqlBytes:
380 case StorageType.SqlChars:
381 return false;
382 default:
383 return dataType.IsValueType;
384 }
385 }
386
387 internal static void ImplementsInterfaces(StorageType typeCode, Type dataType, out bool sqlType, out bool nullable, out bool xmlSerializable, out bool changeTracking, out bool revertibleChangeTracking)
388 {
389 if (IsSqlType(typeCode))
390 {
391 sqlType = true;
392 nullable = true;
393 changeTracking = false;
395 xmlSerializable = true;
396 }
397 else if (typeCode != 0)
398 {
399 sqlType = false;
400 nullable = false;
401 changeTracking = false;
403 xmlSerializable = false;
404 }
405 else
406 {
408 sqlType = false;
409 nullable = orAdd.Item1;
410 changeTracking = orAdd.Item2;
412 xmlSerializable = orAdd.Item4;
413 }
414 }
415
417 {
418 return new Tuple<bool, bool, bool, bool>(typeof(INullable).IsAssignableFrom(dataType), typeof(IChangeTracking).IsAssignableFrom(dataType), typeof(IRevertibleChangeTracking).IsAssignableFrom(dataType), typeof(IXmlSerializable).IsAssignableFrom(dataType));
419 }
420
421 internal static bool ImplementsINullableValue(StorageType typeCode, Type dataType)
422 {
423 if (typeCode == StorageType.Empty && dataType.IsGenericType)
424 {
425 return dataType.GetGenericTypeDefinition() == typeof(Nullable<>);
426 }
427 return false;
428 }
429
430 public static bool IsObjectNull(object value)
431 {
432 if (value != null && DBNull.Value != value)
433 {
434 return IsObjectSqlNull(value);
435 }
436 return true;
437 }
438
439 public static bool IsObjectSqlNull(object value)
440 {
442 {
443 return nullable.IsNull;
444 }
445 return false;
446 }
447
449 {
451 }
452
453 internal void CopyValueInternal(int record, object store, BitArray nullbits, int storeIndex)
454 {
456 }
457
459 {
461 }
462
463 protected abstract object GetEmptyStorage(int recordCount);
464
465 protected abstract void CopyValue(int record, object store, BitArray nullbits, int storeIndex);
466
467 protected abstract void SetStorage(object store, BitArray nullbits);
468
470 {
472 }
473
474 [RequiresUnreferencedCode("Calls Type.GetType")]
475 internal static Type GetType(string value)
476 {
478 if (null == type && "System.Numerics.BigInteger" == value)
479 {
481 }
483 return type;
484 }
485
486 internal static string GetQualifiedName(Type type)
487 {
489 return type.AssemblyQualifiedName;
490 }
491}
void Set(int index, bool value)
Definition BitArray.cs:326
static readonly DBNull Value
Definition DBNull.cs:8
object Get(int recordNo)
DataStorage(DataColumn column, Type type, object defaultValue, object nullValue, bool isICloneable, StorageType storageType)
static bool IsObjectNull(object value)
void Set(int recordNo, object value)
void SetStorage(object store, BitArray nullbits)
void SetNullStorage(BitArray nullbits)
static bool DetermineIfValueType(StorageType typeCode, Type dataType)
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)
object GetEmptyStorage(int recordCount)
static Type GetType(string value)
DataStorage(DataColumn column, Type type, object defaultValue, object nullValue, StorageType storageType)
int CompareValueTo(int recordNo1, object value)
int CompareBits(int recordNo1, int recordNo2)
bool HasValue(int recordNo)
readonly StorageType _storageTypeCode
static readonly Type[] s_storageClassType
readonly DataColumn _column
virtual void SetCapacity(int capacity)
static Type GetTypeStorage(StorageType storageType)
static DataStorage CreateStorage(DataColumn column, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.PublicProperties)] Type dataType, StorageType typeCode)
void CopyValue(int record, object store, BitArray nullbits, int storeIndex)
void SetNullBit(int recordNo, bool flag)
virtual void ConvertObjectToXml(object value, XmlWriter xmlWriter, XmlRootAttribute xmlAttrib)
void CopyBits(int srcRecordNo, int dstRecordNo)
void CopyValueInternal(int record, object store, BitArray nullbits, int storeIndex)
static string GetQualifiedName(Type type)
static bool IsTypeCustomType(StorageType typeCode)
object GetBits(int recordNo)
object AggregateCount(int[] recordNos)
string ConvertObjectToXml(object value)
void SetStorageInternal(object store, BitArray nullbits)
static Tuple< bool, bool, bool, bool > InspectTypeForInterfaces(Type dataType)
virtual int GetStringLength(int record)
object ConvertXmlToObject(string s)
static bool IsTypeCustomType(Type type)
DataStorage(DataColumn column, Type type, object defaultValue, StorageType storageType)
virtual object Aggregate(int[] recordNos, AggregateType kind)
virtual bool IsNull(int recordNo)
static bool IsObjectSqlNull(object value)
readonly DataTable _table
int Compare(int recordNo1, int recordNo2)
static readonly Func< Type, Tuple< bool, bool, bool, bool > > s_inspectTypeForInterfaces
object GetEmptyStorageInternal(int recordCount)
static bool IsSqlType(StorageType storageType)
static StorageType GetStorageType(Type dataType)
virtual object ConvertXmlToObject(XmlReader xmlReader, XmlRootAttribute xmlAttrib)
void Copy(int recordNo1, int recordNo2)
static readonly ConcurrentDictionary< Type, Tuple< bool, bool, bool, bool > > s_typeImplementsInterface
static bool IsSqlType(Type dataType)
static void VerifyIDynamicMetaObjectProvider(Type type)
DataSetDateTime DateTimeMode
IFormatProvider FormatProvider
Definition DataTable.cs:435
static Exception InvalidStorageType(TypeCode typecode)
bool IsValueType
Definition Type.cs:234
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
virtual bool IsGenericType
Definition Type.cs:111
virtual Type GetGenericTypeDefinition()
Definition Type.cs:495
TypeCode
Definition TypeCode.cs:4