From 0e83265ec1131cba2822da6235a2f5a0e3c86940 Mon Sep 17 00:00:00 2001 From: Still Hsu <341464@gmail.com> Date: Sat, 21 Jul 2018 03:07:01 +0800 Subject: [PATCH] Change all Select(... as ...) to OfType --- src/Discord.Net.Core/Extensions/DiscordClientExtensions.cs | 4 ++-- src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs | 6 +++--- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 4 ++-- src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Discord.Net.Core/Extensions/DiscordClientExtensions.cs b/src/Discord.Net.Core/Extensions/DiscordClientExtensions.cs index ff3c7caf7..81cd10b49 100644 --- a/src/Discord.Net.Core/Extensions/DiscordClientExtensions.cs +++ b/src/Discord.Net.Core/Extensions/DiscordClientExtensions.cs @@ -12,12 +12,12 @@ namespace Discord public static async Task GetDMChannelAsync(this IDiscordClient client, ulong id) => await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IDMChannel; public static async Task> GetDMChannelsAsync(this IDiscordClient client) - => (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).Select(x => x as IDMChannel).Where(x => x != null); + => (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).OfType(); public static async Task GetGroupChannelAsync(this IDiscordClient client, ulong id) => await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IGroupChannel; public static async Task> GetGroupChannelsAsync(this IDiscordClient client) - => (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).Select(x => x as IGroupChannel).Where(x => x != null); + => (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).OfType(); public static async Task GetOptimalVoiceRegionAsync(this IDiscordClient discord) { diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 9bf13fa07..e6819e8a4 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -168,7 +168,7 @@ namespace Discord.Rest public async Task> GetTextChannelsAsync(RequestOptions options = null) { var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); - return channels.Select(x => x as RestTextChannel).Where(x => x != null).ToImmutableArray(); + return channels.OfType().ToImmutableArray(); } public async Task GetVoiceChannelAsync(ulong id, RequestOptions options = null) { @@ -178,12 +178,12 @@ namespace Discord.Rest public async Task> GetVoiceChannelsAsync(RequestOptions options = null) { var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); - return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); + return channels.OfType().ToImmutableArray(); } public async Task> GetCategoryChannelsAsync(RequestOptions options = null) { var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); - return channels.Select(x => x as RestCategoryChannel).Where(x => x != null).ToImmutableArray(); + return channels.OfType().ToImmutableArray(); } public async Task GetAFKChannelAsync(RequestOptions options = null) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 9efc7d3fa..4911cc39e 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -63,9 +63,9 @@ namespace Discord.WebSocket public override IReadOnlyCollection Guilds => State.Guilds; public override IReadOnlyCollection PrivateChannels => State.PrivateChannels; public IReadOnlyCollection DMChannels - => State.PrivateChannels.Select(x => x as SocketDMChannel).Where(x => x != null).ToImmutableArray(); + => State.PrivateChannels.OfType().ToImmutableArray(); public IReadOnlyCollection GroupChannels - => State.PrivateChannels.Select(x => x as SocketGroupChannel).Where(x => x != null).ToImmutableArray(); + => State.PrivateChannels.OfType().ToImmutableArray(); public override IReadOnlyCollection VoiceRegions => _voiceRegions.ToReadOnlyCollection(); /// Creates a new REST/WebSocket discord client. diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index bf33ef569..8c9b81ebb 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -91,11 +91,11 @@ namespace Discord.WebSocket } } public IReadOnlyCollection TextChannels - => Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); + => Channels.OfType().ToImmutableArray(); public IReadOnlyCollection VoiceChannels - => Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); + => Channels.OfType().ToImmutableArray(); public IReadOnlyCollection CategoryChannels - => Channels.Select(x => x as SocketCategoryChannel).Where(x => x != null).ToImmutableArray(); + => Channels.OfType().ToImmutableArray(); public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; public SocketRole EveryoneRole => GetRole(Id); public IReadOnlyCollection Channels