From 8ea812cba339db7207159a8e1ebb8a8d780b2ebc Mon Sep 17 00:00:00 2001 From: RogueException Date: Tue, 16 Aug 2016 01:59:01 -0300 Subject: [PATCH] Do not give extension conversion errors if the object is null --- src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs | 4 ++++ src/Discord.Net/WebSocket/Extensions/GuildExtensions.cs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs b/src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs index 10b6f746c..ab9911cac 100644 --- a/src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs +++ b/src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs @@ -31,6 +31,7 @@ namespace Discord.WebSocket internal static SocketDMChannel GetSocketDMChannel(IDMChannel channel) { + Preconditions.NotNull(channel, nameof(channel)); var socketChannel = channel as SocketDMChannel; if (socketChannel == null) throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); @@ -38,6 +39,7 @@ namespace Discord.WebSocket } internal static SocketGroupChannel GetSocketGroupChannel(IGroupChannel channel) { + Preconditions.NotNull(channel, nameof(channel)); var socketChannel = channel as SocketGroupChannel; if (socketChannel == null) throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); @@ -45,6 +47,7 @@ namespace Discord.WebSocket } internal static SocketTextChannel GetSocketTextChannel(ITextChannel channel) { + Preconditions.NotNull(channel, nameof(channel)); var socketChannel = channel as SocketTextChannel; if (socketChannel == null) throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); @@ -52,6 +55,7 @@ namespace Discord.WebSocket } internal static SocketVoiceChannel GetSocketVoiceChannel(IVoiceChannel channel) { + Preconditions.NotNull(channel, nameof(channel)); var socketChannel = channel as SocketVoiceChannel; if (socketChannel == null) throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); diff --git a/src/Discord.Net/WebSocket/Extensions/GuildExtensions.cs b/src/Discord.Net/WebSocket/Extensions/GuildExtensions.cs index 83b9b82f0..a2c5c7882 100644 --- a/src/Discord.Net/WebSocket/Extensions/GuildExtensions.cs +++ b/src/Discord.Net/WebSocket/Extensions/GuildExtensions.cs @@ -41,6 +41,7 @@ namespace Discord.WebSocket //Helpers internal static SocketGuild GetSocketGuild(IGuild guild) { + Preconditions.NotNull(guild, nameof(guild)); var socketGuild = guild as SocketGuild; if (socketGuild == null) throw new InvalidOperationException("This extension method is only valid on WebSocket Entities");