diff options
Diffstat (limited to 'src/Ryujinx.Graphics.Device/SizeCalculator.cs')
-rw-r--r-- | src/Ryujinx.Graphics.Device/SizeCalculator.cs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/Ryujinx.Graphics.Device/SizeCalculator.cs b/src/Ryujinx.Graphics.Device/SizeCalculator.cs deleted file mode 100644 index 54820ec36..000000000 --- a/src/Ryujinx.Graphics.Device/SizeCalculator.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | using System; | ||
2 | using System.Reflection; | ||
3 | |||
4 | namespace Ryujinx.Graphics.Device | ||
5 | { | ||
6 | public static class SizeCalculator | ||
7 | { | ||
8 | public static int SizeOf(Type type) | ||
9 | { | ||
10 | // Is type a enum type? | ||
11 | if (type.IsEnum) | ||
12 | { | ||
13 | type = type.GetEnumUnderlyingType(); | ||
14 | } | ||
15 | |||
16 | // Is type a pointer type? | ||
17 | if (type.IsPointer || type == typeof(IntPtr) || type == typeof(UIntPtr)) | ||
18 | { | ||
19 | return IntPtr.Size; | ||
20 | } | ||
21 | |||
22 | // Is type a struct type? | ||
23 | if (type.IsValueType && !type.IsPrimitive) | ||
24 | { | ||
25 | // Check if the struct has a explicit size, if so, return that. | ||
26 | if (type.StructLayoutAttribute.Size != 0) | ||
27 | { | ||
28 | return type.StructLayoutAttribute.Size; | ||
29 | } | ||
30 | |||
31 | // Otherwise we calculate the sum of the sizes of all fields. | ||
32 | int size = 0; | ||
33 | var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); | ||
34 | |||
35 | for (int fieldIndex = 0; fieldIndex < fields.Length; fieldIndex++) | ||
36 | { | ||
37 | size += SizeOf(fields[fieldIndex].FieldType); | ||
38 | } | ||
39 | |||
40 | return size; | ||
41 | } | ||
42 | |||
43 | // Primitive types. | ||
44 | return (Type.GetTypeCode(type)) switch | ||
45 | { | ||
46 | TypeCode.SByte => sizeof(sbyte), | ||
47 | TypeCode.Byte => sizeof(byte), | ||
48 | TypeCode.Int16 => sizeof(short), | ||
49 | TypeCode.UInt16 => sizeof(ushort), | ||
50 | TypeCode.Int32 => sizeof(int), | ||
51 | TypeCode.UInt32 => sizeof(uint), | ||
52 | TypeCode.Int64 => sizeof(long), | ||
53 | TypeCode.UInt64 => sizeof(ulong), | ||
54 | TypeCode.Char => sizeof(char), | ||
55 | TypeCode.Single => sizeof(float), | ||
56 | TypeCode.Double => sizeof(double), | ||
57 | TypeCode.Decimal => sizeof(decimal), | ||
58 | TypeCode.Boolean => sizeof(bool), | ||
59 | _ => throw new ArgumentException($"Length for type \"{type.Name}\" is unknown."), | ||
60 | }; | ||
61 | } | ||
62 | } | ||
63 | } | ||