From afda0b547121d34c08610babac229ec38213c020 Mon Sep 17 00:00:00 2001 From: Andreas Mueller Date: Fri, 12 Nov 2021 23:59:45 +0100 Subject: [PATCH] =?UTF-8?q?Fallback-Wert=20f=C3=BCr=20JsonDeserialize,=20I?= =?UTF-8?q?nvariantCulture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AMWD.Common/Extensions/JsonExtensions.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AMWD.Common/Extensions/JsonExtensions.cs b/AMWD.Common/Extensions/JsonExtensions.cs index 80fcc8e..7694833 100644 --- a/AMWD.Common/Extensions/JsonExtensions.cs +++ b/AMWD.Common/Extensions/JsonExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Globalization; using System.IO; using System.Text; using Newtonsoft.Json.Linq; @@ -19,7 +20,8 @@ namespace Newtonsoft.Json /// private static readonly JsonSerializerSettings jsonSerializerSettings = new() { - ContractResolver = new CamelCasePropertyNamesContractResolver() + ContractResolver = new CamelCasePropertyNamesContractResolver(), + Culture = CultureInfo.InvariantCulture }; /// @@ -74,13 +76,14 @@ namespace Newtonsoft.Json /// /// The type of the instance to deserialize. /// The JSON string to read the values from. + /// A fallback value. /// A new instance of with the deserialized values. - public static T DeserializeJson(this string json) + public static T DeserializeJson(this string json, T fallback = default) { if (!string.IsNullOrWhiteSpace(json)) return JsonConvert.DeserializeObject(json, jsonSerializerSettings); - return default; + return fallback; } ///