mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
ArrayConverter update for handling exponent notation, EnumConverter fix for writing enum values
This commit is contained in:
parent
a55cd1bb13
commit
4017ac780f
@ -109,13 +109,21 @@ namespace CryptoExchange.Net.Converters
|
|||||||
{
|
{
|
||||||
if (token.Type == JTokenType.Null)
|
if (token.Type == JTokenType.Null)
|
||||||
value = null;
|
value = null;
|
||||||
|
|
||||||
|
if (token.Type == JTokenType.Float)
|
||||||
|
value = token.Value<decimal>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((property.PropertyType == typeof(decimal)
|
if (value is decimal)
|
||||||
|
{
|
||||||
|
property.SetValue(result, value);
|
||||||
|
}
|
||||||
|
else if ((property.PropertyType == typeof(decimal)
|
||||||
|| property.PropertyType == typeof(decimal?))
|
|| property.PropertyType == typeof(decimal?))
|
||||||
&& (value != null && value.ToString().IndexOf("e", StringComparison.OrdinalIgnoreCase) >= 0))
|
&& (value != null && value.ToString().IndexOf("e", StringComparison.OrdinalIgnoreCase) >= 0))
|
||||||
{
|
{
|
||||||
if (decimal.TryParse(value.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture, out var dec))
|
var v = value.ToString();
|
||||||
|
if (decimal.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out var dec))
|
||||||
property.SetValue(result, dec);
|
property.SetValue(result, dec);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -117,9 +117,12 @@ namespace CryptoExchange.Net.Converters
|
|||||||
/// <param name="enumValue"></param>
|
/// <param name="enumValue"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[return: NotNullIfNotNull("enumValue")]
|
[return: NotNullIfNotNull("enumValue")]
|
||||||
public static string? GetString<T>(T enumValue)
|
public static string? GetString<T>(T enumValue) => GetString(typeof(T), enumValue);
|
||||||
|
|
||||||
|
|
||||||
|
[return: NotNullIfNotNull("enumValue")]
|
||||||
|
private static string? GetString(Type objectType, object? enumValue)
|
||||||
{
|
{
|
||||||
var objectType = typeof(T);
|
|
||||||
objectType = Nullable.GetUnderlyingType(objectType) ?? objectType;
|
objectType = Nullable.GetUnderlyingType(objectType) ?? objectType;
|
||||||
|
|
||||||
if (!_mapping.TryGetValue(objectType, out var mapping))
|
if (!_mapping.TryGetValue(objectType, out var mapping))
|
||||||
@ -131,8 +134,15 @@ namespace CryptoExchange.Net.Converters
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
var stringValue = GetString(value);
|
if (value == null)
|
||||||
|
{
|
||||||
|
writer.WriteNull();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var stringValue = GetString(value.GetType(), value);
|
||||||
writer.WriteValue(stringValue);
|
writer.WriteValue(stringValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user