mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-10 13:22:24 +00:00
Use JsonExtensions package
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Internal.Extensions
|
||||
@@ -15,13 +14,5 @@ namespace DiscordChatExporter.Domain.Internal.Extensions
|
||||
await input.CopyToAsync(output);
|
||||
await output.DisposeAsync();
|
||||
}
|
||||
|
||||
public static async ValueTask<JsonElement> ReadAsJsonAsync(this HttpContent content)
|
||||
{
|
||||
await using var stream = await content.ReadAsStreamAsync();
|
||||
using var doc = await JsonDocument.ParseAsync(stream);
|
||||
|
||||
return doc.RootElement.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Internal.Extensions
|
||||
{
|
||||
internal static class JsonElementExtensions
|
||||
{
|
||||
public static JsonElement? GetPropertyOrNull(this JsonElement element, string propertyName) =>
|
||||
element.TryGetProperty(propertyName, out var result) && result.ValueKind != JsonValueKind.Null
|
||||
? result
|
||||
: (JsonElement?) null;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace DiscordChatExporter.Domain.Internal.Extensions
|
||||
{
|
||||
internal static class Utf8JsonWriterExtensions
|
||||
{
|
||||
public static void WriteString(this Utf8JsonWriter writer, string propertyName, DateTimeOffset? value)
|
||||
{
|
||||
writer.WritePropertyName(propertyName);
|
||||
|
||||
if (value != null)
|
||||
writer.WriteStringValue(value.Value);
|
||||
else
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
|
||||
public static void WriteNumber(this Utf8JsonWriter writer, string propertyName, int? value)
|
||||
{
|
||||
writer.WritePropertyName(propertyName);
|
||||
|
||||
if (value != null)
|
||||
writer.WriteNumberValue(value.Value);
|
||||
else
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user