From 16da8a6ad3e49d1b8111393d6038d99376e8797c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Comte?= Date: Sun, 5 Aug 2018 22:09:59 +0200 Subject: [PATCH] Properties can now be optional --- .../Attributes/JsonOptionalPropertyAttribute.cs | 11 +++++++++++ CryptoExchange.Net/ExchangeClient.cs | 7 +++++++ 2 files changed, 18 insertions(+) create mode 100644 CryptoExchange.Net/Attributes/JsonOptionalPropertyAttribute.cs diff --git a/CryptoExchange.Net/Attributes/JsonOptionalPropertyAttribute.cs b/CryptoExchange.Net/Attributes/JsonOptionalPropertyAttribute.cs new file mode 100644 index 0000000..eb298f7 --- /dev/null +++ b/CryptoExchange.Net/Attributes/JsonOptionalPropertyAttribute.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.Attributes +{ + public class JsonOptionalPropertyAttribute : Attribute + { + public JsonOptionalPropertyAttribute() { } + } +} diff --git a/CryptoExchange.Net/ExchangeClient.cs b/CryptoExchange.Net/ExchangeClient.cs index 6bf89cd..ce43d6d 100644 --- a/CryptoExchange.Net/ExchangeClient.cs +++ b/CryptoExchange.Net/ExchangeClient.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using System.Reflection; using System.Threading.Tasks; +using CryptoExchange.Net.Attributes; using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Logging; @@ -294,6 +295,12 @@ namespace CryptoExchange.Net foreach (var prop in properties) { + var propInfo = props.FirstOrDefault(p => p.Name == prop || + ((JsonPropertyAttribute)p.GetCustomAttributes(typeof(JsonPropertyAttribute), false).FirstOrDefault())?.PropertyName == prop); + var optional = propInfo.GetCustomAttributes(typeof(JsonOptionalPropertyAttribute), false).FirstOrDefault(); + if (optional != null) + continue; + isDif = true; log.Write(LogVerbosity.Warning, $"Didn't find key `{prop}` in returned data object of type `{type.Name}`"); }