From 12d75bbc64cf3012722f8036a34a1acf7a5df45d Mon Sep 17 00:00:00 2001 From: haraldwolff Date: Tue, 29 Aug 2023 21:01:32 +0200 Subject: [PATCH] Added implicit operators --- ln.json/JSONNumber.cs | 9 +++++++++ ln.json/JSONString.cs | 2 ++ ln.json/ln.json.csproj | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ln.json/JSONNumber.cs b/ln.json/JSONNumber.cs index e179b78..6e5d3fa 100644 --- a/ln.json/JSONNumber.cs +++ b/ln.json/JSONNumber.cs @@ -64,5 +64,14 @@ namespace ln.json { return decValue.ToString(CultureInfo.InvariantCulture); } + + + public static implicit operator Decimal(JSONNumber j) => j.decValue; + public static implicit operator float(JSONNumber j) => (float)j.decValue; + public static implicit operator double(JSONNumber j) => (double)j.decValue; + public static implicit operator int(JSONNumber j) => (int)j.decValue; + public static implicit operator long(JSONNumber j) => (long)j.decValue; + public static implicit operator uint(JSONNumber j) => (uint)j.decValue; + public static implicit operator ulong(JSONNumber j) => (ulong)j.decValue; } } diff --git a/ln.json/JSONString.cs b/ln.json/JSONString.cs index cacadda..8918cae 100644 --- a/ln.json/JSONString.cs +++ b/ln.json/JSONString.cs @@ -97,5 +97,7 @@ namespace ln.json } return sb.ToString(); } + + public static implicit operator String(JSONString j) => j.Value; } } diff --git a/ln.json/ln.json.csproj b/ln.json/ln.json.csproj index a8eda89..a1531c5 100644 --- a/ln.json/ln.json.csproj +++ b/ln.json/ln.json.csproj @@ -9,7 +9,7 @@ true 0.1.0.0 0.1.0.0 - 1.3.0-preview2 + 1.3.0-preview3 net7.0