-
Notifications
You must be signed in to change notification settings - Fork 189
/
InfoOf.cs
79 lines (76 loc) · 2.35 KB
/
InfoOf.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using NumSharp.Backends;
namespace NumSharp.Utilities
{
/// <summary>
/// Provides a cache for properties of <typeparamref name="T"/> that requires computation.
/// </summary>
/// <typeparam name="T"></typeparam>
[SuppressMessage("ReSharper", "StaticMemberInGenericType")]
public class InfoOf<T>
{
public static readonly int Size;
public static readonly NPTypeCode NPTypeCode;
public static readonly T Zero;
public static readonly T MaxValue;
public static readonly T MinValue;
static InfoOf()
{
NPTypeCode = typeof(T).GetTypeCode();
Zero = default;
try
{
MaxValue = (T)NPTypeCode.MaxValue();
MinValue = (T)NPTypeCode.MinValue();
}
catch (ArgumentOutOfRangeException) { }
switch (NPTypeCode)
{
case NPTypeCode.Boolean:
Size = 1;
break;
case NPTypeCode.Char:
Size = 2;
break;
case NPTypeCode.Byte:
Size = 1;
break;
case NPTypeCode.Int16:
Size = 2;
break;
case NPTypeCode.UInt16:
Size = 2;
break;
case NPTypeCode.Int32:
Size = 4;
break;
case NPTypeCode.UInt32:
Size = 4;
break;
case NPTypeCode.Int64:
Size = 8;
break;
case NPTypeCode.UInt64:
Size = 8;
break;
case NPTypeCode.Single:
Size = 4;
break;
case NPTypeCode.Double:
Size = 8;
break;
case NPTypeCode.Decimal:
Size = 16;
break;
case NPTypeCode.String:
break;
case NPTypeCode.Complex:
default:
Size = Marshal.SizeOf<T>();
break;
}
}
}
}