-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathBigIntConversionHelper.cs
64 lines (48 loc) · 1.67 KB
/
BigIntConversionHelper.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
using System;
using System.Numerics;
namespace Vibrant.InfluxDB.Client.Helpers
{
internal static class BigIntConversionHelper
{
public static object ChangeType(BigInteger value, Type conversionType)
{
if (conversionType == null)
{
throw new ArgumentNullException(nameof(conversionType));
}
switch (Type.GetTypeCode(conversionType))
{
case TypeCode.Boolean:
return value == 1;
case TypeCode.Char:
return (char)value;
case TypeCode.SByte:
return (sbyte)value;
case TypeCode.Byte:
return (byte)value;
case TypeCode.Int16:
return (short)value;
case TypeCode.UInt16:
return (ushort)value;
case TypeCode.Int32:
return (int)value;
case TypeCode.UInt32:
return (uint)value;
case TypeCode.Int64:
return (long)value;
case TypeCode.UInt64:
return (ulong)value;
case TypeCode.Single:
return (float)value;
case TypeCode.Double:
return (double)value;
case TypeCode.Decimal:
return (decimal)value;
case TypeCode.String:
return value.ToString();
default:
throw new NotSupportedException($"Not supported data type: {conversionType}");
}
}
}
}