Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Statics.cs
Go to the documentation of this file.
5using System.Text;
6
8
9internal static class Statics
10{
11 public static readonly TraceLoggingDataType IntPtrType;
12
13 public static readonly TraceLoggingDataType UIntPtrType;
14
15 public static readonly TraceLoggingDataType HexIntPtrType;
16
17 public static byte[] MetadataForString(string name, int prefixSize, int suffixSize, int additionalSize)
18 {
19 CheckName(name);
20 int num = Encoding.UTF8.GetByteCount(name) + 3 + prefixSize + suffixSize;
21 byte[] array = new byte[num];
22 ushort num2 = checked((ushort)(num + additionalSize));
23 array[0] = (byte)num2;
24 array[1] = (byte)(num2 >> 8);
25 Encoding.UTF8.GetBytes(name, 0, name.Length, array, 2 + prefixSize);
26 return array;
27 }
28
29 public static void EncodeTags(int tags, ref int pos, byte[] metadata)
30 {
31 int num = tags & 0xFFFFFFF;
32 bool flag;
33 do
34 {
35 byte b = (byte)((uint)(num >> 21) & 0x7Fu);
36 flag = (num & 0x1FFFFF) != 0;
37 b |= (byte)(flag ? 128u : 0u);
38 num <<= 7;
39 if (metadata != null)
40 {
41 metadata[pos] = b;
42 }
43 pos++;
44 }
45 while (flag);
46 }
47
48 public static byte Combine(int settingValue, byte defaultValue)
49 {
50 if ((byte)settingValue != settingValue)
51 {
52 return defaultValue;
53 }
54 return (byte)settingValue;
55 }
56
57 public static int Combine(int settingValue1, int settingValue2)
58 {
59 if ((byte)settingValue1 != settingValue1)
60 {
61 return settingValue2;
62 }
63 return settingValue1;
64 }
65
66 public static void CheckName(string name)
67 {
68 if (name != null && 0 <= name.IndexOf('\0'))
69 {
70 throw new ArgumentOutOfRangeException("name");
71 }
72 }
73
74 public static bool ShouldOverrideFieldName(string fieldName)
75 {
76 if (fieldName.Length <= 2)
77 {
78 return fieldName[0] == '_';
79 }
80 return false;
81 }
82
87
89 {
90 return format switch
91 {
92 EventFieldFormat.Default => native,
93 EventFieldFormat.String => TraceLoggingDataType.Char8,
94 EventFieldFormat.Boolean => TraceLoggingDataType.Boolean8,
95 EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt8,
97 };
98 }
99
101 {
102 return format switch
103 {
104 EventFieldFormat.Default => native,
105 EventFieldFormat.String => TraceLoggingDataType.Char16,
106 EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt16,
108 };
109 }
110
112 {
113 return format switch
114 {
115 EventFieldFormat.Default => native,
116 EventFieldFormat.Boolean => TraceLoggingDataType.Boolean32,
117 EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt32,
118 EventFieldFormat.HResult => TraceLoggingDataType.HResult,
120 };
121 }
122
124 {
125 return format switch
126 {
127 EventFieldFormat.Default => native,
128 EventFieldFormat.Hexadecimal => TraceLoggingDataType.HexInt64,
130 };
131 }
132
134 {
135 switch (nativeFormat)
136 {
137 case TraceLoggingDataType.Int8:
138 case TraceLoggingDataType.UInt8:
139 case TraceLoggingDataType.Boolean8:
140 return Format8(format, nativeFormat);
141 case TraceLoggingDataType.Int16:
142 case TraceLoggingDataType.UInt16:
143 case TraceLoggingDataType.Char16:
144 return Format16(format, nativeFormat);
145 case TraceLoggingDataType.Int32:
146 case TraceLoggingDataType.UInt32:
147 case TraceLoggingDataType.Float:
148 return Format32(format, nativeFormat);
149 case TraceLoggingDataType.Int64:
150 case TraceLoggingDataType.UInt64:
151 case TraceLoggingDataType.Double:
152 return Format64(format, nativeFormat);
153 default:
154 return MakeDataType(nativeFormat, format);
155 }
156 }
157
158 public static bool HasCustomAttribute(PropertyInfo propInfo, Type attributeType)
159 {
160 return propInfo.IsDefined(attributeType, inherit: false);
161 }
162
163 public static AttributeType GetCustomAttribute<AttributeType>(PropertyInfo propInfo) where AttributeType : Attribute
164 {
165 AttributeType result = null;
166 object[] customAttributes = propInfo.GetCustomAttributes(typeof(AttributeType), inherit: false);
167 if (customAttributes.Length != 0)
168 {
169 return (AttributeType)customAttributes[0];
170 }
171 return result;
172 }
173
174 public static AttributeType GetCustomAttribute<AttributeType>(Type type) where AttributeType : Attribute
175 {
176 AttributeType result = null;
177 object[] customAttributes = type.GetCustomAttributes(typeof(AttributeType), inherit: false);
178 if (customAttributes.Length != 0)
179 {
180 return (AttributeType)customAttributes[0];
181 }
182 return result;
183 }
184
186 {
187 Type type2 = null;
189 {
190 type2 = type.GetGenericArguments()[0];
191 }
192 else
193 {
195 Type[] array2 = array;
196 foreach (Type type3 in array2)
197 {
198 if (type2 != null)
199 {
200 type2 = null;
201 break;
202 }
203 type2 = type3.GetGenericArguments()[0];
204 }
205 }
206 return type2;
207 }
208
209 public static bool IsGenericMatch(Type type, object openType)
210 {
211 if (type.IsGenericType)
212 {
213 return type.GetGenericTypeDefinition() == (Type)openType;
214 }
215 return false;
216 }
217
218 [RequiresUnreferencedCode("EventSource WriteEvent will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
220 {
221 if (recursionCheck.Contains(dataType))
222 {
224 }
225 recursionCheck.Add(dataType);
228 {
230 return new InvokeTypeInfo(dataType, typeAnalysis);
231 }
232 if (dataType.IsArray)
233 {
234 Type elementType = dataType.GetElementType();
235 if (elementType == typeof(bool))
236 {
238 }
239 if (elementType == typeof(byte))
240 {
241 return ScalarArrayTypeInfo.Byte();
242 }
243 if (elementType == typeof(sbyte))
244 {
245 return ScalarArrayTypeInfo.SByte();
246 }
247 if (elementType == typeof(short))
248 {
249 return ScalarArrayTypeInfo.Int16();
250 }
251 if (elementType == typeof(ushort))
252 {
254 }
255 if (elementType == typeof(int))
256 {
257 return ScalarArrayTypeInfo.Int32();
258 }
259 if (elementType == typeof(uint))
260 {
262 }
263 if (elementType == typeof(long))
264 {
265 return ScalarArrayTypeInfo.Int64();
266 }
267 if (elementType == typeof(ulong))
268 {
270 }
271 if (elementType == typeof(char))
272 {
273 return ScalarArrayTypeInfo.Char();
274 }
275 if (elementType == typeof(double))
276 {
278 }
279 if (elementType == typeof(float))
280 {
282 }
283 if (elementType == typeof(IntPtr))
284 {
286 }
287 if (elementType == typeof(UIntPtr))
288 {
290 }
291 if (elementType == typeof(Guid))
292 {
293 return ScalarArrayTypeInfo.Guid();
294 }
296 }
297 if (dataType.IsEnum)
298 {
299 dataType = Enum.GetUnderlyingType(dataType);
300 }
301 if (dataType == typeof(string))
302 {
303 return StringTypeInfo.Instance();
304 }
305 if (dataType == typeof(bool))
306 {
307 return ScalarTypeInfo.Boolean();
308 }
309 if (dataType == typeof(byte))
310 {
311 return ScalarTypeInfo.Byte();
312 }
313 if (dataType == typeof(sbyte))
314 {
315 return ScalarTypeInfo.SByte();
316 }
317 if (dataType == typeof(short))
318 {
319 return ScalarTypeInfo.Int16();
320 }
321 if (dataType == typeof(ushort))
322 {
323 return ScalarTypeInfo.UInt16();
324 }
325 if (dataType == typeof(int))
326 {
327 return ScalarTypeInfo.Int32();
328 }
329 if (dataType == typeof(uint))
330 {
331 return ScalarTypeInfo.UInt32();
332 }
333 if (dataType == typeof(long))
334 {
335 return ScalarTypeInfo.Int64();
336 }
337 if (dataType == typeof(ulong))
338 {
339 return ScalarTypeInfo.UInt64();
340 }
341 if (dataType == typeof(char))
342 {
343 return ScalarTypeInfo.Char();
344 }
345 if (dataType == typeof(double))
346 {
347 return ScalarTypeInfo.Double();
348 }
349 if (dataType == typeof(float))
350 {
351 return ScalarTypeInfo.Single();
352 }
353 if (dataType == typeof(DateTime))
354 {
355 return DateTimeTypeInfo.Instance();
356 }
357 if (dataType == typeof(decimal))
358 {
359 return DecimalTypeInfo.Instance();
360 }
361 if (dataType == typeof(IntPtr))
362 {
363 return ScalarTypeInfo.IntPtr();
364 }
365 if (dataType == typeof(UIntPtr))
366 {
367 return ScalarTypeInfo.UIntPtr();
368 }
369 if (dataType == typeof(Guid))
370 {
371 return ScalarTypeInfo.Guid();
372 }
373 if (dataType == typeof(TimeSpan))
374 {
375 return TimeSpanTypeInfo.Instance();
376 }
377 if (dataType == typeof(DateTimeOffset))
378 {
380 }
381 if (dataType == typeof(EmptyStruct))
382 {
383 return NullTypeInfo.Instance();
384 }
385 if (IsGenericMatch(dataType, typeof(Nullable<>)))
386 {
387 return new NullableTypeInfo(dataType, recursionCheck);
388 }
390 if (type != null)
391 {
393 }
395 }
396
397 static Statics()
398 {
399 if (IntPtr.Size != 8)
400 {
401 }
403 if (IntPtr.Size != 8)
404 {
405 }
407 if (IntPtr.Size != 8)
408 {
409 }
411 }
412}
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static TraceLoggingTypeInfo Instance()
static TraceLoggingTypeInfo Instance()
static unsafe TraceLoggingTypeInfo Guid()
static TraceLoggingTypeInfo UInt32()
static TraceLoggingTypeInfo Char()
static TraceLoggingTypeInfo Int32()
static TraceLoggingTypeInfo Guid()
static TraceLoggingTypeInfo Single()
static TraceLoggingTypeInfo UInt64()
static TraceLoggingTypeInfo UInt16()
static TraceLoggingTypeInfo UIntPtr()
static TraceLoggingTypeInfo SByte()
static TraceLoggingTypeInfo Boolean()
static TraceLoggingTypeInfo Int64()
static TraceLoggingTypeInfo Int16()
static TraceLoggingTypeInfo Byte()
static TraceLoggingTypeInfo Double()
static TraceLoggingTypeInfo IntPtr()
static bool ShouldOverrideFieldName(string fieldName)
Definition Statics.cs:74
static Type FindEnumerableElementType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type)
Definition Statics.cs:185
static readonly TraceLoggingDataType UIntPtrType
Definition Statics.cs:13
static TraceLoggingDataType Format64(EventFieldFormat format, TraceLoggingDataType native)
Definition Statics.cs:123
static TraceLoggingDataType FormatScalar(EventFieldFormat format, TraceLoggingDataType nativeFormat)
Definition Statics.cs:133
static TraceLoggingTypeInfo CreateDefaultTypeInfo(Type dataType, List< Type > recursionCheck)
Definition Statics.cs:219
static TraceLoggingDataType Format8(EventFieldFormat format, TraceLoggingDataType native)
Definition Statics.cs:88
static byte[] MetadataForString(string name, int prefixSize, int suffixSize, int additionalSize)
Definition Statics.cs:17
static TraceLoggingDataType Format32(EventFieldFormat format, TraceLoggingDataType native)
Definition Statics.cs:111
static readonly TraceLoggingDataType HexIntPtrType
Definition Statics.cs:15
static void CheckName(string name)
Definition Statics.cs:66
static bool IsGenericMatch(Type type, object openType)
Definition Statics.cs:209
static AttributeType GetCustomAttribute< AttributeType >(PropertyInfo propInfo)
Definition Statics.cs:163
static TraceLoggingDataType Format16(EventFieldFormat format, TraceLoggingDataType native)
Definition Statics.cs:100
static TraceLoggingDataType MakeDataType(TraceLoggingDataType baseType, EventFieldFormat format)
Definition Statics.cs:83
static void EncodeTags(int tags, ref int pos, byte[] metadata)
Definition Statics.cs:29
static bool HasCustomAttribute(PropertyInfo propInfo, Type attributeType)
Definition Statics.cs:158
static readonly TraceLoggingDataType IntPtrType
Definition Statics.cs:11
static int Combine(int settingValue1, int settingValue2)
Definition Statics.cs:57
static byte Combine(int settingValue, byte defaultValue)
Definition Statics.cs:48
static TraceLoggingTypeInfo Instance()
static TraceLoggingTypeInfo GetInstance(Type type, List< Type > recursionCheck)
static Type GetUnderlyingType(Type enumType)
Definition Enum.cs:309
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string EventSource_NonCompliantTypeError
Definition SR.cs:1254
static string EventSource_RecursiveTypeDefinition
Definition SR.cs:1272
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
Type? GetElementType()
virtual Type[] FindInterfaces(TypeFilter filter, object? filterCriteria)
Definition Type.cs:1300
bool IsArray
Definition Type.cs:71
virtual bool IsEnum
Definition Type.cs:227
static int Size
Definition IntPtr.cs:21