1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-20 12:53:02 +00:00

Updated threadsafefilewriter to check single instance, added Exception catch to deserialize

This commit is contained in:
JKorf
2018-05-04 10:52:38 +02:00
parent 754f49e0c4
commit 56d5bbcdf4
4 changed files with 44 additions and 16 deletions
+14 -4
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
@@ -25,10 +26,19 @@ namespace CryptoExchange.Net.Converters
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var val = Mapping.SingleOrDefault(v => v.Value == reader.Value.ToString()).Key;
if (val != null)
return val;
return Mapping.Single(v => v.Value.ToLower() == reader.Value.ToString().ToLower()).Key;
if (reader.Value == null)
return null;
var value = reader.Value.ToString();
if (Mapping.ContainsValue(value))
return Mapping.Single(m => m.Value == value).Key;
var lowerResult = Mapping.SingleOrDefault(m => m.Value.ToLower() == value.ToLower());
if (!lowerResult.Equals(default(KeyValuePair<T, string>)))
return lowerResult.Value;
Debug.WriteLine($"Cannot map enum. Type: {typeof(T)}, Value: {value}");
return null;
}
public T ReadString(string data)