Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataRowComparer.cs
Go to the documentation of this file.
2
3namespace System.Data;
4
5public static class DataRowComparer
6{
8
9 internal static bool AreEqual(object a, object b)
10 {
11 if (a == b)
12 {
13 return true;
14 }
15 if (a == null || a == DBNull.Value || b == null || b == DBNull.Value)
16 {
17 return false;
18 }
19 if (!a.Equals(b))
20 {
21 if (a.GetType().IsArray)
22 {
23 return CompareArray((Array)a, b as Array);
24 }
25 return false;
26 }
27 return true;
28 }
29
30 private static bool AreElementEqual(object a, object b)
31 {
32 if (a == b)
33 {
34 return true;
35 }
36 if (a == null || a == DBNull.Value || b == null || b == DBNull.Value)
37 {
38 return false;
39 }
40 return a.Equals(b);
41 }
42
43 private static bool CompareArray(Array a, Array b)
44 {
45 if (b == null || 1 != a.Rank || 1 != b.Rank || a.Length != b.Length)
46 {
47 return false;
48 }
49 int num = a.GetLowerBound(0);
50 int num2 = b.GetLowerBound(0);
51 if (a.GetType() == b.GetType() && num == 0 && num2 == 0)
52 {
53 switch (Type.GetTypeCode(a.GetType().GetElementType()))
54 {
55 case TypeCode.Byte:
56 return CompareEquatableArray((byte[])a, (byte[])b);
57 case TypeCode.Int16:
58 return CompareEquatableArray((short[])a, (short[])b);
59 case TypeCode.Int32:
60 return CompareEquatableArray((int[])a, (int[])b);
61 case TypeCode.Int64:
62 return CompareEquatableArray((long[])a, (long[])b);
63 case TypeCode.String:
64 return CompareEquatableArray((string[])a, (string[])b);
65 }
66 }
67 int num3 = num + a.Length;
68 while (num < num3)
69 {
70 if (!AreElementEqual(a.GetValue(num), b.GetValue(num2)))
71 {
72 return false;
73 }
74 num++;
75 num2++;
76 }
77 return true;
78 }
79
81 {
82 for (int num = 0; num < a.Length; num++)
83 {
84 ref TElem reference = ref a[num];
85 TElem val = default(TElem);
86 bool num2;
87 if (val == null)
88 {
89 val = reference;
90 reference = ref val;
91 if (val == null)
92 {
93 num2 = b[num] != null;
94 goto IL_0054;
95 }
96 }
97 num2 = !reference.Equals(b[num]);
98 goto IL_0054;
99 IL_0054:
100 if (num2)
101 {
102 return false;
103 }
104 }
105 return true;
106 }
107}
109{
111
113
115 {
116 }
117
119 {
120 if (leftRow == rightRow)
121 {
122 return true;
123 }
124 if (leftRow == null || rightRow == null)
125 {
126 return false;
127 }
128 if (leftRow.RowState == DataRowState.Deleted || rightRow.RowState == DataRowState.Deleted)
129 {
131 }
132 int count = leftRow.Table.Columns.Count;
133 if (count != rightRow.Table.Columns.Count)
134 {
135 return false;
136 }
137 for (int i = 0; i < count; i++)
138 {
140 {
141 return false;
142 }
143 }
144 return true;
145 }
146
147 public int GetHashCode(TRow row)
148 {
149 DataSetUtil.CheckArgumentNull(row, "row");
150 if (row.RowState == DataRowState.Deleted)
151 {
153 }
154 int result = 0;
155 if (row.Table.Columns.Count > 0)
156 {
157 object obj = row[0];
158 Type type = obj.GetType();
159 if (!type.IsArray)
160 {
161 result = ((!(obj is ValueType valueType)) ? obj.GetHashCode() : valueType.GetHashCode());
162 }
163 else
164 {
165 Array array = (Array)obj;
166 if (array.Rank > 1)
167 {
168 result = obj.GetHashCode();
169 }
170 else if (array.Length > 0)
171 {
172 result = array.GetValue(array.GetLowerBound(0)).GetHashCode();
173 }
174 }
175 }
176 return result;
177 }
178}
static InvalidOperationException InvalidOperation(string message)
static readonly DBNull Value
Definition DBNull.cs:8
static bool CompareArray(Array a, Array b)
static DataRowComparer< DataRow > Default
static readonly DataRowComparer< TRow > s_instance
static bool AreElementEqual(object a, object b)
bool Equals(TRow? leftRow, TRow? rightRow)
static bool AreEqual(object a, object b)
static bool CompareEquatableArray< TElem >(TElem[] a, TElem[] b)
static string DataSetLinq_CannotCompareDeletedRow
Definition SR.cs:932
Definition SR.cs:7
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
TypeCode
Definition TypeCode.cs:4