Browse Source

Do not give extension conversion errors if the object is null

pull/204/head
RogueException 8 years ago
parent
commit
8ea812cba3
2 changed files with 5 additions and 0 deletions
  1. +4
    -0
      src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs
  2. +1
    -0
      src/Discord.Net/WebSocket/Extensions/GuildExtensions.cs

+ 4
- 0
src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs View File

@@ -31,6 +31,7 @@ namespace Discord.WebSocket


internal static SocketDMChannel GetSocketDMChannel(IDMChannel channel) internal static SocketDMChannel GetSocketDMChannel(IDMChannel channel)
{ {
Preconditions.NotNull(channel, nameof(channel));
var socketChannel = channel as SocketDMChannel; var socketChannel = channel as SocketDMChannel;
if (socketChannel == null) if (socketChannel == null)
throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); 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) internal static SocketGroupChannel GetSocketGroupChannel(IGroupChannel channel)
{ {
Preconditions.NotNull(channel, nameof(channel));
var socketChannel = channel as SocketGroupChannel; var socketChannel = channel as SocketGroupChannel;
if (socketChannel == null) if (socketChannel == null)
throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); 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) internal static SocketTextChannel GetSocketTextChannel(ITextChannel channel)
{ {
Preconditions.NotNull(channel, nameof(channel));
var socketChannel = channel as SocketTextChannel; var socketChannel = channel as SocketTextChannel;
if (socketChannel == null) if (socketChannel == null)
throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); 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) internal static SocketVoiceChannel GetSocketVoiceChannel(IVoiceChannel channel)
{ {
Preconditions.NotNull(channel, nameof(channel));
var socketChannel = channel as SocketVoiceChannel; var socketChannel = channel as SocketVoiceChannel;
if (socketChannel == null) if (socketChannel == null)
throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); throw new InvalidOperationException("This extension method is only valid on WebSocket Entities");


+ 1
- 0
src/Discord.Net/WebSocket/Extensions/GuildExtensions.cs View File

@@ -41,6 +41,7 @@ namespace Discord.WebSocket
//Helpers //Helpers
internal static SocketGuild GetSocketGuild(IGuild guild) internal static SocketGuild GetSocketGuild(IGuild guild)
{ {
Preconditions.NotNull(guild, nameof(guild));
var socketGuild = guild as SocketGuild; var socketGuild = guild as SocketGuild;
if (socketGuild == null) if (socketGuild == null)
throw new InvalidOperationException("This extension method is only valid on WebSocket Entities"); throw new InvalidOperationException("This extension method is only valid on WebSocket Entities");


Loading…
Cancel
Save