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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user