From c1725c2a185f0eccc772cc9a5f3a0f157488900b Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 19 Aug 2019 14:14:15 +0200 Subject: [PATCH] JSONValue.ToNative() added --- JSONNumber.cs | 8 +++++++- JSONString.cs | 1 + JSONValue.cs | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) 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;