Skip to content

Commit 0f07610

Browse files
author
Dan Duong
committed
Add ulong support.
1 parent a5df8b8 commit 0f07610

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

SimpleJSON.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ public virtual long AsLong
324324
}
325325
}
326326

327+
public virtual ulong AsULong
328+
{
329+
get
330+
{
331+
ulong val = 0;
332+
if (ulong.TryParse(Value, out val))
333+
return val;
334+
return 0;
335+
}
336+
set
337+
{
338+
Value = value.ToString();
339+
}
340+
}
341+
327342
public virtual JSONArray AsArray
328343
{
329344
get
@@ -392,6 +407,17 @@ public static implicit operator long(JSONNode d)
392407
return (d == null) ? 0L : d.AsLong;
393408
}
394409

410+
public static implicit operator JSONNode(ulong n)
411+
{
412+
if (longAsString)
413+
return new JSONString(n.ToString());
414+
return new JSONNumber(n);
415+
}
416+
public static implicit operator ulong(JSONNode d)
417+
{
418+
return (d == null) ? 0 : d.AsULong;
419+
}
420+
395421
public static implicit operator JSONNode(bool b)
396422
{
397423
return new JSONBool(b);
@@ -1051,6 +1077,11 @@ public override long AsLong
10511077
get { return (long)m_Data; }
10521078
set { m_Data = value; }
10531079
}
1080+
public override ulong AsULong
1081+
{
1082+
get { return (ulong)m_Data; }
1083+
set { m_Data = value; }
1084+
}
10541085

10551086
public JSONNumber(double aData)
10561087
{
@@ -1320,6 +1351,25 @@ public override long AsLong
13201351
}
13211352
}
13221353

1354+
public override ulong AsULong
1355+
{
1356+
get
1357+
{
1358+
if (longAsString)
1359+
Set(new JSONString("0"));
1360+
else
1361+
Set(new JSONNumber(0.0));
1362+
return 0L;
1363+
}
1364+
set
1365+
{
1366+
if (longAsString)
1367+
Set(new JSONString(value.ToString()));
1368+
else
1369+
Set(new JSONNumber(value));
1370+
}
1371+
}
1372+
13231373
public override bool AsBool
13241374
{
13251375
get { Set(new JSONBool(false)); return false; }

0 commit comments

Comments
 (0)