From 89d41a27503cd493fe948d66fa2ed5d8782fc869 Mon Sep 17 00:00:00 2001 From: rafael-aero Date: Thu, 26 Aug 2021 16:08:11 +0200 Subject: [PATCH] restore serialization settings where it makes sense --- ElectronNET.API/Clipboard.cs | 9 ++++++++- ElectronNET.API/Cookies.cs | 12 ++++++++++-- ElectronNET.API/Dialog.cs | 13 ++++++++++--- ElectronNET.API/Notification.cs | 9 ++++++++- ElectronNET.API/WindowManager.cs | 23 ++++++++++++++++------- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/ElectronNET.API/Clipboard.cs b/ElectronNET.API/Clipboard.cs index f9e0fb4..3e8e87a 100644 --- a/ElectronNET.API/Clipboard.cs +++ b/ElectronNET.API/Clipboard.cs @@ -158,7 +158,7 @@ namespace ElectronNET.API /// public void Write(Data data, string type = "") { - BridgeConnector.Emit("clipboard-write", data, type); + BridgeConnector.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type); } /// @@ -177,5 +177,12 @@ namespace ElectronNET.API { BridgeConnector.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type); } + + private static JsonSerializer _jsonSerializer = new JsonSerializer() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore + }; } } \ No newline at end of file diff --git a/ElectronNET.API/Cookies.cs b/ElectronNET.API/Cookies.cs index 67f16b0..dce7de0 100644 --- a/ElectronNET.API/Cookies.cs +++ b/ElectronNET.API/Cookies.cs @@ -71,7 +71,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(cookies); }); - BridgeConnector.Emit("webContents-session-cookies-get", Id, filter, guid); + BridgeConnector.Emit("webContents-session-cookies-get", Id, JObject.FromObject(filter, _jsonSerializer), guid); return taskCompletionSource.Task; } @@ -92,7 +92,7 @@ namespace ElectronNET.API taskCompletionSource.SetResult(null); }); - BridgeConnector.Emit("webContents-session-cookies-set", Id, details, guid); + BridgeConnector.Emit("webContents-session-cookies-set", Id, JObject.FromObject(details, _jsonSerializer), guid); return taskCompletionSource.Task; } @@ -138,5 +138,13 @@ namespace ElectronNET.API return taskCompletionSource.Task; } + + private static JsonSerializer _jsonSerializer = new JsonSerializer() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore + }; + } } \ No newline at end of file diff --git a/ElectronNET.API/Dialog.cs b/ElectronNET.API/Dialog.cs index 6011e1d..af81e28 100644 --- a/ElectronNET.API/Dialog.cs +++ b/ElectronNET.API/Dialog.cs @@ -159,12 +159,12 @@ namespace ElectronNET.API }); - if (browserWindow == null) + if (browserWindow is null) { - BridgeConnector.Emit("showMessageBox", messageBoxOptions, guid); + BridgeConnector.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer), guid); } else { - BridgeConnector.Emit("showMessageBox", browserWindow , messageBoxOptions, guid); + BridgeConnector.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer), JObject.FromObject(messageBoxOptions, _jsonSerializer), guid); } return taskCompletionSource.Task; @@ -224,5 +224,12 @@ namespace ElectronNET.API return taskCompletionSource.Task; } + + private static JsonSerializer _jsonSerializer = new JsonSerializer() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore + }; } } diff --git a/ElectronNET.API/Notification.cs b/ElectronNET.API/Notification.cs index 7f93f96..86d9ac3 100644 --- a/ElectronNET.API/Notification.cs +++ b/ElectronNET.API/Notification.cs @@ -48,7 +48,7 @@ namespace ElectronNET.API { GenerateIDsForDefinedActions(notificationOptions); - BridgeConnector.Emit("createNotification", notificationOptions); + BridgeConnector.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer)); } private static void GenerateIDsForDefinedActions(NotificationOptions notificationOptions) @@ -134,5 +134,12 @@ namespace ElectronNET.API return taskCompletionSource.Task; } + + private static JsonSerializer _jsonSerializer = new JsonSerializer() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore + }; } } diff --git a/ElectronNET.API/WindowManager.cs b/ElectronNET.API/WindowManager.cs index e8869d3..712df60 100644 --- a/ElectronNET.API/WindowManager.cs +++ b/ElectronNET.API/WindowManager.cs @@ -134,7 +134,7 @@ namespace ElectronNET.API options.X = 0; options.Y = 0; - BridgeConnector.Emit("createBrowserWindow", options, loadUrl); + BridgeConnector.Emit("createBrowserWindow", JObject.FromObject(options, _jsonSerializer), loadUrl); } else { @@ -145,13 +145,9 @@ namespace ElectronNET.API options.X = options.X - 7; } - var ownjsonSerializer = new JsonSerializer() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; - BridgeConnector.Emit("createBrowserWindow", JObject.FromObject(options, ownjsonSerializer), loadUrl); + + BridgeConnector.Emit("createBrowserWindow", JObject.FromObject(options, _keepDefaultValuesSerializer), loadUrl); } return taskCompletionSource.Task; @@ -205,5 +201,18 @@ namespace ElectronNET.API return taskCompletionSource.Task; } + + private static JsonSerializer _jsonSerializer = new JsonSerializer() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Ignore + }; + + private static JsonSerializer _keepDefaultValuesSerializer = new JsonSerializer() + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }; } }