Use `[]` in place of `Array.Empty<T>()`

pull/1220/head
Tyrrrz 1 month ago
parent 6d1e8c2e02
commit 12b590d9f9

@ -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<Channel>();
: [];
foreach (var channel in channels)
{

@ -63,7 +63,7 @@ public partial record Embed
json.GetPropertyOrNull("fields")
?.EnumerateArrayOrNull()
?.Select(EmbedField.Parse)
.ToArray() ?? Array.Empty<EmbedField>();
.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<EmbedImage>();
.ToArray() ?? [];
var video = json.GetPropertyOrNull("video")?.Pipe(EmbedVideo.Parse);

@ -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<Snowflake>());
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<Snowflake>();
.ToArray() ?? [];
var avatarUrl = guildId is not null
? json.GetPropertyOrNull("avatar")

@ -144,28 +144,28 @@ public partial record Message
json.GetPropertyOrNull("attachments")
?.EnumerateArrayOrNull()
?.Select(Attachment.Parse)
.ToArray() ?? Array.Empty<Attachment>();
.ToArray() ?? [];
var embeds = NormalizeEmbeds(
json.GetPropertyOrNull("embeds")?.EnumerateArrayOrNull()?.Select(Embed.Parse).ToArray()
?? Array.Empty<Embed>()
?? []
);
var stickers =
json.GetPropertyOrNull("sticker_items")
?.EnumerateArrayOrNull()
?.Select(Sticker.Parse)
.ToArray() ?? Array.Empty<Sticker>();
.ToArray() ?? [];
var reactions =
json.GetPropertyOrNull("reactions")
?.EnumerateArrayOrNull()
?.Select(Reaction.Parse)
.ToArray() ?? Array.Empty<Reaction>();
.ToArray() ?? [];
var mentionedUsers =
json.GetPropertyOrNull("mentions")?.EnumerateArrayOrNull()?.Select(User.Parse).ToArray()
?? Array.Empty<User>();
?? [];
var messageReference = json.GetPropertyOrNull("message_reference")
?.Pipe(MessageReference.Parse);

@ -97,7 +97,7 @@ internal class ExportContext(DiscordClient discord, ExportRequest request)
.Select(TryGetRole)
.WhereNotNull()
.OrderByDescending(r => r.Position)
.ToArray() ?? Array.Empty<Role>();
.ToArray() ?? [];
public Color? TryGetUserColor(Snowflake id) =>
GetUserRoles(id).Where(r => r.Color is not null).Select(r => r.Color).FirstOrDefault();

Loading…
Cancel
Save