From 1a73ecf89a5fecb657cdcf506deb16b706241cc6 Mon Sep 17 00:00:00 2001 From: Artem Kurianov <artemkuryanov@gmail.com> Date: Thu, 20 Aug 2020 16:47:34 +0000 Subject: [PATCH] setted checking object parameter at Deserialize<T> to optional for backward compatibility, and added the same config field for preventing checking objects at Stream deserializing. added checking type for not null at CheckObject --- CryptoExchange.Net/BaseClient.cs | 14 +++++++++++--- CryptoExchange.Net/Objects/Options.cs | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CryptoExchange.Net/BaseClient.cs b/CryptoExchange.Net/BaseClient.cs index b01e1a1..8e73049 100644 --- a/CryptoExchange.Net/BaseClient.cs +++ b/CryptoExchange.Net/BaseClient.cs @@ -36,6 +36,10 @@ namespace CryptoExchange.Net /// The auth provider /// </summary> protected internal AuthenticationProvider? authProvider; + /// <summary> + /// Should check received objects + /// </summary> + public bool ShouldCheckObjects { get; set; } /// <summary> /// The last used id @@ -73,6 +77,7 @@ namespace CryptoExchange.Net apiProxy = options.Proxy; log.Write(LogVerbosity.Debug, $"Client configuration: {options}"); + ShouldCheckObjects = options.ShouldCheckObjects; } /// <summary> @@ -128,7 +133,7 @@ namespace CryptoExchange.Net /// <param name="checkObject">Whether or not the parsing should be checked for missing properties (will output data to the logging if log verbosity is Debug)</param> /// <param name="serializer">A specific serializer to use</param> /// <returns></returns> - protected CallResult<T> Deserialize<T>(string data, bool checkObject = true, JsonSerializer? serializer = null) + protected CallResult<T> Deserialize<T>(string data, bool? checkObject = null, JsonSerializer? serializer = null) { var tokenResult = ValidateJson(data); if (!tokenResult) @@ -148,14 +153,14 @@ namespace CryptoExchange.Net /// <param name="checkObject">Whether or not the parsing should be checked for missing properties (will output data to the logging if log verbosity is Debug)</param> /// <param name="serializer">A specific serializer to use</param> /// <returns></returns> - protected CallResult<T> Deserialize<T>(JToken obj, bool checkObject = true, JsonSerializer? serializer = null) + protected CallResult<T> Deserialize<T>(JToken obj, bool? checkObject = null, JsonSerializer? serializer = null) { if (serializer == null) serializer = defaultSerializer; try { - if (checkObject && log.Level == LogVerbosity.Debug) + if ((checkObject ?? ShouldCheckObjects)&& log.Level == LogVerbosity.Debug) { try { @@ -256,6 +261,9 @@ namespace CryptoExchange.Net private void CheckObject(Type type, JObject obj) { + if (type == null) + return; + if (type.GetCustomAttribute<JsonConverterAttribute>(true) != null) // If type has a custom JsonConverter we assume this will handle property mapping return; diff --git a/CryptoExchange.Net/Objects/Options.cs b/CryptoExchange.Net/Objects/Options.cs index 577de1e..80354a7 100644 --- a/CryptoExchange.Net/Objects/Options.cs +++ b/CryptoExchange.Net/Objects/Options.cs @@ -84,8 +84,10 @@ namespace CryptoExchange.Net.Objects /// The api credentials /// </summary> public ApiCredentials? ApiCredentials { get; set; } - - + /// <summary> + /// ShoouldCheckObjects + /// </summary> + public bool ShouldCheckObjects { get; set; } = true; /// <summary> /// Proxy to use /// </summary>