forked from izrik/FbxSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber.cs
More file actions
49 lines (41 loc) · 1.18 KB
/
Number.cs
File metadata and controls
49 lines (41 loc) · 1.18 KB
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
using System;
using System.Globalization;
namespace FbxSharp
{
public struct Number
{
public Number(string str)
{
if (string.IsNullOrWhiteSpace(str)) throw new ArgumentNullException("s");
StringRepresentation = str;
double d;
if (double.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out d))
AsDouble = d;
else
AsDouble = null;
long l;
if (long.TryParse(str, out l))
AsLong = l;
else
AsLong = null;
if (!AsLong.HasValue && !AsDouble.HasValue)
{
throw new ArgumentException("The string cannot be interpreted as a number", "str");
}
}
public readonly string StringRepresentation;
public readonly double? AsDouble;
public readonly long? AsLong;
public override string ToString()
{
if (AsLong.HasValue)
{
return AsLong.Value.ToString();
}
else
{
return AsDouble.Value.ToString();
}
}
}
}