mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
wip
This commit is contained in:
parent
a0e2f78a6a
commit
9f6eb9f0d0
@ -134,14 +134,15 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
||||
if (att == null)
|
||||
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
|
||||
{
|
||||
ArrayProperty = att,
|
||||
PropertyInfo = property,
|
||||
DefaultDeserialization = property.GetCustomAttribute<CryptoExchange.Net.Attributes.JsonConversionAttribute>() != null,
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -29,7 +29,11 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
||||
/// </summary>
|
||||
/// <param name="enumValue"></param>
|
||||
/// <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
|
||||
#endif
|
||||
=> EnumConverter<T>.GetString(enumValue);
|
||||
|
||||
/// <summary>
|
||||
@ -38,7 +42,11 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
||||
/// <param name="enumValue"></param>
|
||||
/// <returns></returns>
|
||||
[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
|
||||
#endif
|
||||
=> EnumConverter<T>.GetString(enumValue);
|
||||
}
|
||||
|
||||
|
@ -10,5 +10,14 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
|
||||
[AttributeUsage(System.AttributeTargets.Class | AttributeTargets.Enum | System.AttributeTargets.Interface)]
|
||||
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 />
|
||||
public class SystemTextJsonMessageSerializer : IMessageSerializer
|
||||
{
|
||||
private readonly JsonSerializerContext _options;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public SystemTextJsonMessageSerializer(JsonSerializerContext options)
|
||||
public SystemTextJsonMessageSerializer(JsonSerializerOptions 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", "IL3050:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
|
||||
#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);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Generate a random string of specified length
|
||||
/// </summary>
|
||||
|
@ -103,10 +103,6 @@ namespace CryptoExchange.Net.SharedApis
|
||||
/// Required optional parameters in the request
|
||||
/// </summary>
|
||||
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>
|
||||
/// ctor
|
||||
@ -156,8 +152,6 @@ namespace CryptoExchange.Net.SharedApis
|
||||
sb.AppendLine(RequestNotes);
|
||||
if (RequiredOptionalParameters.Any())
|
||||
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())
|
||||
sb.AppendLine($"Required exchange specific parameters: {string.Join(", ", RequiredExchangeParameters.Select(x => x.ToString()))}");
|
||||
if (OptionalExchangeParameters.Any())
|
||||
|
@ -16,9 +16,13 @@ namespace CryptoExchange.Net.SharedApis
|
||||
/// </summary>
|
||||
public DateTime? DeliveryTime { get; set; }
|
||||
/// <summary>
|
||||
/// Max leverage setting
|
||||
/// Max short leverage setting
|
||||
/// </summary>
|
||||
public decimal? MaxLeverage { get; set; }
|
||||
public decimal? MaxShortLeverage { get; set; }
|
||||
/// <summary>
|
||||
/// Max long leverage setting
|
||||
/// </summary>
|
||||
public decimal? MaxLongLeverage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
|
Loading…
x
Reference in New Issue
Block a user