Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TimeSpanStorage.cs
Go to the documentation of this file.
3using System.Xml;
4
5namespace System.Data.Common;
6
7internal sealed class TimeSpanStorage : DataStorage
8{
9 private static readonly TimeSpan s_defaultValue = TimeSpan.Zero;
10
11 private TimeSpan[] _values;
12
17
18 public override object Aggregate(int[] records, AggregateType kind)
19 {
20 bool flag = false;
21 try
22 {
23 switch (kind)
24 {
25 case AggregateType.Min:
26 {
28 foreach (int num9 in records)
29 {
30 if (!IsNull(num9))
31 {
33 flag = true;
34 }
35 }
36 if (flag)
37 {
38 return timeSpan;
39 }
40 return _nullValue;
41 }
42 case AggregateType.Max:
43 {
45 foreach (int num13 in records)
46 {
47 if (!IsNull(num13))
48 {
50 flag = true;
51 }
52 }
53 if (flag)
54 {
55 return timeSpan2;
56 }
57 return _nullValue;
58 }
59 case AggregateType.First:
60 if (records.Length != 0)
61 {
62 return _values[records[0]];
63 }
64 return null;
65 case AggregateType.Count:
66 return base.Aggregate(records, kind);
67 case AggregateType.Sum:
68 {
69 decimal d = default(decimal);
70 foreach (int num14 in records)
71 {
72 if (!IsNull(num14))
73 {
74 d += (decimal)_values[num14].Ticks;
75 flag = true;
76 }
77 }
78 if (flag)
79 {
80 return TimeSpan.FromTicks((long)Math.Round(d));
81 }
82 return null;
83 }
84 case AggregateType.Mean:
85 {
86 decimal num10 = default(decimal);
87 int num11 = 0;
88 foreach (int num12 in records)
89 {
90 if (!IsNull(num12))
91 {
92 num10 += (decimal)_values[num12].Ticks;
93 num11++;
94 }
95 }
96 if (num11 > 0)
97 {
98 return TimeSpan.FromTicks((long)Math.Round(num10 / (decimal)num11));
99 }
100 return null;
101 }
102 case AggregateType.StDev:
103 {
104 int num = 0;
105 decimal num2 = default(decimal);
106 foreach (int num3 in records)
107 {
108 if (!IsNull(num3))
109 {
110 num2 += (decimal)_values[num3].Ticks;
111 num++;
112 }
113 }
114 if (num > 1)
115 {
116 double num4 = 0.0;
117 decimal num5 = num2 / (decimal)num;
118 foreach (int num6 in records)
119 {
120 if (!IsNull(num6))
121 {
122 double num7 = (double)((decimal)_values[num6].Ticks - num5);
123 num4 += num7 * num7;
124 }
125 }
126 ulong num8 = (ulong)Math.Round(Math.Sqrt(num4 / (double)(num - 1)));
127 if (num8 > long.MaxValue)
128 {
129 num8 = 9223372036854775807uL;
130 }
131 return TimeSpan.FromTicks((long)num8);
132 }
133 return null;
134 }
135 case AggregateType.Var:
136 break;
137 }
138 }
139 catch (OverflowException)
140 {
142 }
144 }
145
146 public override int Compare(int recordNo1, int recordNo2)
147 {
151 {
152 int num = CompareBits(recordNo1, recordNo2);
153 if (num != 0)
154 {
155 return num;
156 }
157 }
159 }
160
161 public override int CompareValueTo(int recordNo, object value)
162 {
163 if (_nullValue == value)
164 {
165 if (IsNull(recordNo))
166 {
167 return 0;
168 }
169 return 1;
170 }
173 {
174 return -1;
175 }
177 }
178
179 private static TimeSpan ConvertToTimeSpan(object value)
180 {
182 if (type == typeof(string))
183 {
184 return TimeSpan.Parse((string)value);
185 }
186 if (type == typeof(int))
187 {
188 return new TimeSpan((int)value);
189 }
190 if (type == typeof(long))
191 {
192 return new TimeSpan((long)value);
193 }
194 return (TimeSpan)value;
195 }
196
197 public override object ConvertValue(object value)
198 {
199 if (_nullValue != value)
200 {
201 value = ((value == null) ? _nullValue : ((object)ConvertToTimeSpan(value)));
202 }
203 return value;
204 }
205
206 public override void Copy(int recordNo1, int recordNo2)
207 {
210 }
211
212 public override object Get(int record)
213 {
216 {
217 return timeSpan;
218 }
219 return GetBits(record);
220 }
221
222 public override void Set(int record, object value)
223 {
224 if (_nullValue == value)
225 {
227 SetNullBit(record, flag: true);
228 }
229 else
230 {
232 SetNullBit(record, flag: false);
233 }
234 }
235
236 public override void SetCapacity(int capacity)
237 {
239 if (_values != null)
240 {
242 }
243 _values = array;
244 base.SetCapacity(capacity);
245 }
246
247 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
248 public override object ConvertXmlToObject(string s)
249 {
250 return XmlConvert.ToTimeSpan(s);
251 }
252
253 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
254 public override string ConvertObjectToXml(object value)
255 {
257 }
258
259 protected override object GetEmptyStorage(int recordCount)
260 {
261 return new TimeSpan[recordCount];
262 }
263
264 protected override void CopyValue(int record, object store, BitArray nullbits, int storeIndex)
265 {
269 }
270
271 protected override void SetStorage(object store, BitArray nullbits)
272 {
275 }
276}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void SetNullStorage(BitArray nullbits)
int CompareBits(int recordNo1, int recordNo2)
void SetNullBit(int recordNo, bool flag)
void CopyBits(int srcRecordNo, int dstRecordNo)
object GetBits(int recordNo)
override int CompareValueTo(int recordNo, object value)
override void Copy(int recordNo1, int recordNo2)
override int Compare(int recordNo1, int recordNo2)
override void SetStorage(object store, BitArray nullbits)
override object Get(int record)
static readonly TimeSpan s_defaultValue
override object Aggregate(int[] records, AggregateType kind)
override void CopyValue(int record, object store, BitArray nullbits, int storeIndex)
static TimeSpan ConvertToTimeSpan(object value)
override object GetEmptyStorage(int recordCount)
override void Set(int record, object value)
override string ConvertObjectToXml(object value)
override void SetCapacity(int capacity)
override object ConvertValue(object value)
override object ConvertXmlToObject(string s)
static Exception AggregateException(AggregateType aggregateType, Type type)
static Exception Overflow(Type type)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static double Sqrt(double d)
static decimal Round(decimal d)
Definition Math.cs:1096
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static string ToString(bool value)
static TimeSpan ToTimeSpan(string s)
static readonly TimeSpan MinValue
Definition TimeSpan.cs:25
static int Compare(TimeSpan t1, TimeSpan t2)
Definition TimeSpan.cs:113
static readonly TimeSpan MaxValue
Definition TimeSpan.cs:23
static readonly TimeSpan Zero
Definition TimeSpan.cs:21
int CompareTo(object? value)
Definition TimeSpan.cs:126
static TimeSpan FromTicks(long value)
Definition TimeSpan.cs:277
static TimeSpan Parse(string s)
Definition TimeSpan.cs:301