From 12b590d9f97009a4638d45af7950d5d19aec96fc Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 28 Mar 2024 03:22:44 +0200 Subject: [PATCH] Use `[]` in place of `Array.Empty()` --- DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs | 3 +-- DiscordChatExporter.Core/Discord/Data/Embeds/Embed.cs | 4 ++-- DiscordChatExporter.Core/Discord/Data/Member.cs | 8 +++----- DiscordChatExporter.Core/Discord/Data/Message.cs | 10 +++++----- DiscordChatExporter.Core/Exporting/ExportContext.cs | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index a430cac1..60b152fe 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -7,7 +7,6 @@ using DiscordChatExporter.Cli.Commands.Base; using DiscordChatExporter.Cli.Commands.Converters; using DiscordChatExporter.Cli.Commands.Shared; using DiscordChatExporter.Core.Discord; -using DiscordChatExporter.Core.Discord.Data; using DiscordChatExporter.Core.Utils.Extensions; namespace DiscordChatExporter.Cli.Commands; @@ -59,7 +58,7 @@ public class GetChannelsCommand : DiscordCommandBase ) .OrderBy(c => c.Name) .ToArray() - : Array.Empty(); + : []; foreach (var channel in channels) { diff --git a/DiscordChatExporter.Core/Discord/Data/Embeds/Embed.cs b/DiscordChatExporter.Core/Discord/Data/Embeds/Embed.cs index ccc42d92..8779be70 100644 --- a/DiscordChatExporter.Core/Discord/Data/Embeds/Embed.cs +++ b/DiscordChatExporter.Core/Discord/Data/Embeds/Embed.cs @@ -63,7 +63,7 @@ public partial record Embed json.GetPropertyOrNull("fields") ?.EnumerateArrayOrNull() ?.Select(EmbedField.Parse) - .ToArray() ?? Array.Empty(); + .ToArray() ?? []; var thumbnail = json.GetPropertyOrNull("thumbnail")?.Pipe(EmbedImage.Parse); @@ -78,7 +78,7 @@ public partial record Embed json.GetPropertyOrNull("image") ?.Pipe(EmbedImage.Parse) .ToSingletonEnumerable() - .ToArray() ?? Array.Empty(); + .ToArray() ?? []; var video = json.GetPropertyOrNull("video")?.Pipe(EmbedVideo.Parse); diff --git a/DiscordChatExporter.Core/Discord/Data/Member.cs b/DiscordChatExporter.Core/Discord/Data/Member.cs index ce92e569..d023f373 100644 --- a/DiscordChatExporter.Core/Discord/Data/Member.cs +++ b/DiscordChatExporter.Core/Discord/Data/Member.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text.Json; using DiscordChatExporter.Core.Discord.Data.Common; @@ -21,8 +20,7 @@ public partial record Member( public partial record Member { - public static Member CreateFallback(User user) => - new(user, null, null, Array.Empty()); + public static Member CreateFallback(User user) => new(user, null, null, []); public static Member Parse(JsonElement json, Snowflake? guildId = null) { @@ -34,7 +32,7 @@ public partial record Member ?.EnumerateArray() .Select(j => j.GetNonWhiteSpaceString()) .Select(Snowflake.Parse) - .ToArray() ?? Array.Empty(); + .ToArray() ?? []; var avatarUrl = guildId is not null ? json.GetPropertyOrNull("avatar") diff --git a/DiscordChatExporter.Core/Discord/Data/Message.cs b/DiscordChatExporter.Core/Discord/Data/Message.cs index f7616473..a7b19ed1 100644 --- a/DiscordChatExporter.Core/Discord/Data/Message.cs +++ b/DiscordChatExporter.Core/Discord/Data/Message.cs @@ -144,28 +144,28 @@ public partial record Message json.GetPropertyOrNull("attachments") ?.EnumerateArrayOrNull() ?.Select(Attachment.Parse) - .ToArray() ?? Array.Empty(); + .ToArray() ?? []; var embeds = NormalizeEmbeds( json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray() - ?? Array.Empty() + ?? [] ); var stickers = json.GetPropertyOrNull("sticker_items") ?.EnumerateArrayOrNull() ?.Select(Sticker.Parse) - .ToArray() ?? Array.Empty(); + .ToArray() ?? []; var reactions = json.GetPropertyOrNull("reactions") ?.EnumerateArrayOrNull() ?.Select(Reaction.Parse) - .ToArray() ?? Array.Empty(); + .ToArray() ?? []; var mentionedUsers = json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray() - ?? Array.Empty(); + ?? []; var messageReference = json.GetPropertyOrNull("message_reference") ?.Pipe(MessageReference.Parse); diff --git a/DiscordChatExporter.Core/Exporting/ExportContext.cs b/DiscordChatExporter.Core/Exporting/ExportContext.cs index 224c5aa1..c4dca3fe 100644 --- a/DiscordChatExporter.Core/Exporting/ExportContext.cs +++ b/DiscordChatExporter.Core/Exporting/ExportContext.cs @@ -97,7 +97,7 @@ internal class ExportContext(DiscordClient discord, ExportRequest request) .Select(TryGetRole) .WhereNotNull() .OrderByDescending(r => r.Position) - .ToArray() ?? Array.Empty(); + .ToArray() ?? []; public Color? TryGetUserColor(Snowflake id) => GetUserRoles(id).Where(r => r.Color is not null).Select(r => r.Color).FirstOrDefault();