mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-16 06:20:34 +00:00
Add another useful json helper
This commit is contained in:
@@ -26,7 +26,6 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using ArchiSteamFarm.Core;
|
using ArchiSteamFarm.Core;
|
||||||
using ArchiSteamFarm.Helpers.Json;
|
using ArchiSteamFarm.Helpers.Json;
|
||||||
@@ -50,7 +49,7 @@ internal sealed class Bot {
|
|||||||
throw new InvalidOperationException(nameof(constructor));
|
throw new InvalidOperationException(nameof(constructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement emptyObject = new JsonObject().ToJsonElement();
|
JsonObject emptyObject = new();
|
||||||
|
|
||||||
BotConfig? botConfig = emptyObject.ToJsonObject<BotConfig>();
|
BotConfig? botConfig = emptyObject.ToJsonObject<BotConfig>();
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ internal sealed class MobileAuthenticator {
|
|||||||
["shared_secret"] = sharedSecret
|
["shared_secret"] = sharedSecret
|
||||||
};
|
};
|
||||||
|
|
||||||
Steam.Security.MobileAuthenticator? result = jsonObject.ToJsonElement().ToJsonObject<Steam.Security.MobileAuthenticator>();
|
Steam.Security.MobileAuthenticator? result = jsonObject.ToJsonObject<Steam.Security.MobileAuthenticator>();
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw new InvalidOperationException(nameof(result));
|
throw new InvalidOperationException(nameof(result));
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using System.Text.Json.Serialization.Metadata;
|
using System.Text.Json.Serialization.Metadata;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -55,6 +56,10 @@ public static class JsonUtilities {
|
|||||||
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
|
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
|
||||||
public static T? ToJsonObject<T>(this JsonElement jsonElement) => jsonElement.Deserialize<T>(DefaultJsonSerialierOptions);
|
public static T? ToJsonObject<T>(this JsonElement jsonElement) => jsonElement.Deserialize<T>(DefaultJsonSerialierOptions);
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
|
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
|
||||||
|
public static T? ToJsonObject<T>(this JsonNode jsonNode) => jsonNode.Deserialize<T>(DefaultJsonSerialierOptions);
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
|
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
|
||||||
public static async ValueTask<T?> ToJsonObject<T>(this Stream stream, CancellationToken cancellationToken = default) {
|
public static async ValueTask<T?> ToJsonObject<T>(this Stream stream, CancellationToken cancellationToken = default) {
|
||||||
|
|||||||
Reference in New Issue
Block a user