Use System.Text.Json instead of Newtonsoft.Json

This commit is contained in:
Alexey Golub
2020-04-21 18:15:28 +03:00
parent f153aad3f1
commit 130c0b6fe2
14 changed files with 195 additions and 179 deletions

View File

@@ -1,18 +0,0 @@
using System;
using System.Drawing;
namespace DiscordChatExporter.Core.Services.Internal
{
internal static class Extensions
{
public static DateTimeOffset ToDateTimeOffset(this DateTime dateTime) => new DateTimeOffset(dateTime);
public static string ToSnowflake(this DateTimeOffset dateTime)
{
var value = ((ulong) dateTime.ToUnixTimeMilliseconds() - 1420070400000UL) << 22;
return value.ToString();
}
public static Color ResetAlpha(this Color color) => Color.FromArgb(1, color);
}
}

View File

@@ -0,0 +1,9 @@
using System.Drawing;
namespace DiscordChatExporter.Core.Services.Internal.Extensions
{
internal static class ColorExtensions
{
public static Color ResetAlpha(this Color color) => Color.FromArgb(1, color);
}
}

View File

@@ -0,0 +1,13 @@
using System;
namespace DiscordChatExporter.Core.Services.Internal.Extensions
{
internal static class DateExtensions
{
public static string ToSnowflake(this DateTimeOffset dateTime)
{
var value = ((ulong) dateTime.ToUnixTimeMilliseconds() - 1420070400000UL) << 22;
return value.ToString();
}
}
}

View File

@@ -0,0 +1,9 @@
using System;
namespace DiscordChatExporter.Core.Services.Internal.Extensions
{
internal static class GenericExtensions
{
public static TOut Pipe<TIn, TOut>(this TIn input, Func<TIn, TOut> transform) => transform(input);
}
}

View File

@@ -0,0 +1,12 @@
using System.Text.Json;
namespace DiscordChatExporter.Core.Services.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;
}
}

View File

@@ -0,0 +1,13 @@
using System.Text.Json;
namespace DiscordChatExporter.Core.Services.Internal
{
internal static class Json
{
public static JsonElement Parse(string json)
{
using var document = JsonDocument.Parse(json);
return document.RootElement.Clone();
}
}
}