diff --git a/JSONNumber.cs b/JSONNumber.cs index 147e107..cddfabf 100644 --- a/JSONNumber.cs +++ b/JSONNumber.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using System.Reflection; namespace ln.json { public class JSONNumber : JSONValue @@ -8,6 +7,13 @@ namespace ln.json public Decimal Decimal => decValue; readonly decimal decValue; + public override object ToNative() + { + if (Decimal.Ceiling(decValue).Equals(Decimal.Floor(decValue))) + return (long)decValue; + return (double)decValue; + } + public JSONNumber(int i) : this((long)i) { } diff --git a/JSONString.cs b/JSONString.cs index c5d7e4a..9455f71 100644 --- a/JSONString.cs +++ b/JSONString.cs @@ -17,6 +17,7 @@ namespace ln.json }; public string Value { get; private set; } + public override object ToNative() => Value; public JSONString(String value) :base(JSONValueType.STRING) diff --git a/JSONValue.cs b/JSONValue.cs index 6bbf6ce..f725b69 100644 --- a/JSONValue.cs +++ b/JSONValue.cs @@ -22,6 +22,8 @@ namespace ln.json public virtual bool HasChildren => false; public virtual IEnumerable Children => throw new NotSupportedException(); + public virtual object ToNative() => throw new NotImplementedException(); + public JSONValue(JSONValueType valueType) { ValueType = valueType;