-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathTableExtensions.cs
70 lines (57 loc) · 2.35 KB
/
TableExtensions.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
using System;
using System.Globalization;
using System.Numerics;
namespace Nekoyume.TableData
{
public static class TableExtensions
{
public static bool TryParseDecimal(string value, out decimal result) =>
decimal.TryParse(value, NumberStyles.Number, NumberFormatInfo.InvariantInfo, out result);
public static bool TryParseFloat(string value, out float result) =>
float.TryParse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out result);
public static bool TryParseLong(string value, out long result) =>
long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result);
public static bool TryParseInt(string value, out int result) =>
int.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result);
public static bool ParseBool(string value, bool defaultValue) =>
bool.TryParse(value, out var result) ? result : defaultValue;
public static int ParseInt(string value)
{
if (TryParseInt(value, out var result))
{
return result;
}
throw new ArgumentException(value);
}
public static int ParseInt(string value, int defaultValue) =>
TryParseInt(value, out var result) ? result : defaultValue;
public static decimal ParseDecimal(string value)
{
if (TryParseDecimal(value, out var result))
{
return result;
}
throw new ArgumentException(value);
}
public static decimal ParseDecimal(string value, decimal defaultValue) =>
TryParseDecimal(value, out var result) ? result : defaultValue;
public static long ParseLong(string value)
{
if (TryParseLong(value, out var result))
{
return result;
}
throw new ArgumentException(value);
}
public static long ParseLong(string value, long defaultValue) =>
TryParseLong(value, out var result) ? result : defaultValue;
public static BigInteger ParseBigInteger(string value)
{
if (BigInteger.TryParse(value, out var result))
{
return result;
}
throw new ArgumentException(value);
}
}
}