Skip to content

Commit

Permalink
Use [] in place of Array.Empty<T>()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Mar 28, 2024
1 parent 6d1e8c2 commit 12b590d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
Expand Down Expand Up @@ -59,7 +58,7 @@ public override async ValueTask ExecuteAsync(IConsole console)
)
.OrderBy(c => c.Name)
.ToArray()
: Array.Empty<Channel>();
: [];

foreach (var channel in channels)
{
Expand Down
4 changes: 2 additions & 2 deletions DiscordChatExporter.Core/Discord/Data/Embeds/Embed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Embed Parse(JsonElement json)
json.GetPropertyOrNull("fields")
?.EnumerateArrayOrNull()
?.Select(EmbedField.Parse)
.ToArray() ?? Array.Empty<EmbedField>();
.ToArray() ?? [];

var thumbnail = json.GetPropertyOrNull("thumbnail")?.Pipe(EmbedImage.Parse);

Expand All @@ -78,7 +78,7 @@ public static Embed Parse(JsonElement json)
json.GetPropertyOrNull("image")
?.Pipe(EmbedImage.Parse)
.ToSingletonEnumerable()
.ToArray() ?? Array.Empty<EmbedImage>();
.ToArray() ?? [];

var video = json.GetPropertyOrNull("video")?.Pipe(EmbedVideo.Parse);

Expand Down
8 changes: 3 additions & 5 deletions DiscordChatExporter.Core/Discord/Data/Member.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,8 +20,7 @@ IReadOnlyList<Snowflake> RoleIds

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)
{
Expand All @@ -34,7 +32,7 @@ public static Member Parse(JsonElement json, Snowflake? guildId = null)
?.EnumerateArray()
.Select(j => j.GetNonWhiteSpaceString())
.Select(Snowflake.Parse)
.ToArray() ?? Array.Empty<Snowflake>();
.ToArray() ?? [];

var avatarUrl = guildId is not null
? json.GetPropertyOrNull("avatar")
Expand Down
10 changes: 5 additions & 5 deletions DiscordChatExporter.Core/Discord/Data/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,28 @@ public static Message Parse(JsonElement json)
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);
Expand Down
2 changes: 1 addition & 1 deletion DiscordChatExporter.Core/Exporting/ExportContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ await foreach (var role in Discord.GetGuildRolesAsync(Request.Guild.Id, cancella
.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();
Expand Down

0 comments on commit 12b590d

Please sign in to comment.