mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
wip
This commit is contained in:
parent
a0e2f78a6a
commit
9f6eb9f0d0
@ -134,14 +134,15 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
if (att == null)
|
if (att == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var converterType = property.GetCustomAttribute<JsonConverterAttribute>()?.ConverterType ?? property.PropertyType.GetCustomAttribute<JsonConverterAttribute>()?.ConverterType;
|
var targetType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
|
||||||
|
var converterType = property.GetCustomAttribute<JsonConverterAttribute>()?.ConverterType ?? targetType.GetCustomAttribute<JsonConverterAttribute>()?.ConverterType;
|
||||||
attributes.Add(new ArrayPropertyInfo
|
attributes.Add(new ArrayPropertyInfo
|
||||||
{
|
{
|
||||||
ArrayProperty = att,
|
ArrayProperty = att,
|
||||||
PropertyInfo = property,
|
PropertyInfo = property,
|
||||||
DefaultDeserialization = property.GetCustomAttribute<CryptoExchange.Net.Attributes.JsonConversionAttribute>() != null,
|
DefaultDeserialization = property.GetCustomAttribute<CryptoExchange.Net.Attributes.JsonConversionAttribute>() != null,
|
||||||
JsonConverter = converterType == null ? null : (JsonConverter)Activator.CreateInstance(converterType)!,
|
JsonConverter = converterType == null ? null : (JsonConverter)Activator.CreateInstance(converterType)!,
|
||||||
TargetType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType
|
TargetType = targetType
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +196,8 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
_converterOptionsCache.TryAdd(attribute.JsonConverter, newOptions);
|
_converterOptionsCache.TryAdd(attribute.JsonConverter, newOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = JsonDocument.ParseValue(ref reader).Deserialize(attribute.PropertyInfo.PropertyType, newOptions);
|
var doc = JsonDocument.ParseValue(ref reader);
|
||||||
|
value = doc.Deserialize(attribute.PropertyInfo.PropertyType, newOptions);
|
||||||
}
|
}
|
||||||
else if (attribute.DefaultDeserialization)
|
else if (attribute.DefaultDeserialization)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,11 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="enumValue"></param>
|
/// <param name="enumValue"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
#if NET5_0_OR_GREATER
|
||||||
|
public static string GetString<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields)] T>(T enumValue) where T : struct, Enum
|
||||||
|
#else
|
||||||
public static string GetString<T>(T enumValue) where T : struct, Enum
|
public static string GetString<T>(T enumValue) where T : struct, Enum
|
||||||
|
#endif
|
||||||
=> EnumConverter<T>.GetString(enumValue);
|
=> EnumConverter<T>.GetString(enumValue);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -38,7 +42,11 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
/// <param name="enumValue"></param>
|
/// <param name="enumValue"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[return: NotNullIfNotNull("enumValue")]
|
[return: NotNullIfNotNull("enumValue")]
|
||||||
|
#if NET5_0_OR_GREATER
|
||||||
|
public static string? GetString<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields)] T>(T? enumValue) where T : struct, Enum
|
||||||
|
#else
|
||||||
public static string? GetString<T>(T? enumValue) where T : struct, Enum
|
public static string? GetString<T>(T? enumValue) where T : struct, Enum
|
||||||
|
#endif
|
||||||
=> EnumConverter<T>.GetString(enumValue);
|
=> EnumConverter<T>.GetString(enumValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,5 +10,14 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
[AttributeUsage(System.AttributeTargets.Class | AttributeTargets.Enum | System.AttributeTargets.Interface)]
|
[AttributeUsage(System.AttributeTargets.Class | AttributeTargets.Enum | System.AttributeTargets.Interface)]
|
||||||
public class SerializationModelAttribute : Attribute
|
public class SerializationModelAttribute : Attribute
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
public SerializationModelAttribute() { }
|
||||||
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
public SerializationModelAttribute(Type type) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public class SystemTextJsonMessageSerializer : IMessageSerializer
|
public class SystemTextJsonMessageSerializer : IMessageSerializer
|
||||||
{
|
{
|
||||||
private readonly JsonSerializerContext _options;
|
private readonly JsonSerializerOptions _options;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SystemTextJsonMessageSerializer(JsonSerializerContext options)
|
public SystemTextJsonMessageSerializer(JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
_options = options;
|
_options = options;
|
||||||
}
|
}
|
||||||
@ -24,6 +24,6 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
|||||||
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
|
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
|
||||||
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3050:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
|
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3050:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
|
||||||
#endif
|
#endif
|
||||||
public string Serialize<T>(T message) => JsonSerializer.Serialize(message, SerializerOptions.WithConverters(_options));
|
public string Serialize<T>(T message) => JsonSerializer.Serialize(message, _options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,6 +192,26 @@ namespace CryptoExchange.Net
|
|||||||
return new string(randomChars);
|
return new string(randomChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate a long value
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="maxLength">Max character length</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static long RandomLong(int maxLength)
|
||||||
|
{
|
||||||
|
#if NETSTANDARD2_1_OR_GREATER || NET9_0_OR_GREATER
|
||||||
|
var value = RandomNumberGenerator.GetInt32(0, int.MaxValue);
|
||||||
|
#else
|
||||||
|
var random = new Random();
|
||||||
|
var value = random.Next(0, int.MaxValue);
|
||||||
|
#endif
|
||||||
|
var val = value.ToString();
|
||||||
|
if (val.Length > maxLength)
|
||||||
|
return int.Parse(val.Substring(0, maxLength));
|
||||||
|
else
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a random string of specified length
|
/// Generate a random string of specified length
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -103,10 +103,6 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
/// Required optional parameters in the request
|
/// Required optional parameters in the request
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ParameterDescription> RequiredOptionalParameters { get; set; } = new List<ParameterDescription>();
|
public List<ParameterDescription> RequiredOptionalParameters { get; set; } = new List<ParameterDescription>();
|
||||||
/// <summary>
|
|
||||||
/// Unsupported optional parameters in the request
|
|
||||||
/// </summary>
|
|
||||||
public List<ParameterDescription> UnsupportedOptionalParameters { get; set; } = new List<ParameterDescription>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
@ -156,8 +152,6 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
sb.AppendLine(RequestNotes);
|
sb.AppendLine(RequestNotes);
|
||||||
if (RequiredOptionalParameters.Any())
|
if (RequiredOptionalParameters.Any())
|
||||||
sb.AppendLine($"Required optional parameters: {string.Join(", ", RequiredOptionalParameters.Select(x => x.ToString()))}");
|
sb.AppendLine($"Required optional parameters: {string.Join(", ", RequiredOptionalParameters.Select(x => x.ToString()))}");
|
||||||
if (UnsupportedOptionalParameters.Any())
|
|
||||||
sb.AppendLine($"Unsupported optional specific parameters: {string.Join(", ", UnsupportedOptionalParameters.Select(x => x.ToString()))}");
|
|
||||||
if (RequiredExchangeParameters.Any())
|
if (RequiredExchangeParameters.Any())
|
||||||
sb.AppendLine($"Required exchange specific parameters: {string.Join(", ", RequiredExchangeParameters.Select(x => x.ToString()))}");
|
sb.AppendLine($"Required exchange specific parameters: {string.Join(", ", RequiredExchangeParameters.Select(x => x.ToString()))}");
|
||||||
if (OptionalExchangeParameters.Any())
|
if (OptionalExchangeParameters.Any())
|
||||||
|
@ -16,9 +16,13 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? DeliveryTime { get; set; }
|
public DateTime? DeliveryTime { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Max leverage setting
|
/// Max short leverage setting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal? MaxLeverage { get; set; }
|
public decimal? MaxShortLeverage { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Max long leverage setting
|
||||||
|
/// </summary>
|
||||||
|
public decimal? MaxLongLeverage { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user