Visual Studio C#7 suggestions

This commit is contained in:
Christopher F
2017-04-23 15:23:06 -04:00
parent 6000b15c4d
commit 431b7fbd9f
21 changed files with 80 additions and 165 deletions

View File

@@ -41,15 +41,13 @@ namespace Discord.WebSocket
internal SocketChannel GetChannel(ulong id)
{
SocketChannel channel;
if (_channels.TryGetValue(id, out channel))
if (_channels.TryGetValue(id, out SocketChannel channel))
return channel;
return null;
}
internal SocketDMChannel GetDMChannel(ulong userId)
{
SocketDMChannel channel;
if (_dmChannels.TryGetValue(userId, out channel))
if (_dmChannels.TryGetValue(userId, out SocketDMChannel channel))
return channel;
return null;
}
@@ -57,31 +55,25 @@ namespace Discord.WebSocket
{
_channels[channel.Id] = channel;
var dmChannel = channel as SocketDMChannel;
if (dmChannel != null)
if (channel is SocketDMChannel dmChannel)
_dmChannels[dmChannel.Recipient.Id] = dmChannel;
else
{
var groupChannel = channel as SocketGroupChannel;
if (groupChannel != null)
if (channel is SocketGroupChannel groupChannel)
_groupChannels.TryAdd(groupChannel.Id);
}
}
internal SocketChannel RemoveChannel(ulong id)
{
SocketChannel channel;
if (_channels.TryRemove(id, out channel))
if (_channels.TryRemove(id, out SocketChannel channel))
{
var dmChannel = channel as SocketDMChannel;
if (dmChannel != null)
if (channel is SocketDMChannel dmChannel)
{
SocketDMChannel ignored;
_dmChannels.TryRemove(dmChannel.Recipient.Id, out ignored);
_dmChannels.TryRemove(dmChannel.Recipient.Id, out SocketDMChannel ignored);
}
else
{
var groupChannel = channel as SocketGroupChannel;
if (groupChannel != null)
if (channel is SocketGroupChannel groupChannel)
_groupChannels.TryRemove(id);
}
return channel;
@@ -91,8 +83,7 @@ namespace Discord.WebSocket
internal SocketGuild GetGuild(ulong id)
{
SocketGuild guild;
if (_guilds.TryGetValue(id, out guild))
if (_guilds.TryGetValue(id, out SocketGuild guild))
return guild;
return null;
}
@@ -102,16 +93,14 @@ namespace Discord.WebSocket
}
internal SocketGuild RemoveGuild(ulong id)
{
SocketGuild guild;
if (_guilds.TryRemove(id, out guild))
if (_guilds.TryRemove(id, out SocketGuild guild))
return guild;
return null;
}
internal SocketGlobalUser GetUser(ulong id)
{
SocketGlobalUser user;
if (_users.TryGetValue(id, out user))
if (_users.TryGetValue(id, out SocketGlobalUser user))
return user;
return null;
}
@@ -121,8 +110,7 @@ namespace Discord.WebSocket
}
internal SocketGlobalUser RemoveUser(ulong id)
{
SocketGlobalUser user;
if (_users.TryRemove(id, out user))
if (_users.TryRemove(id, out SocketGlobalUser user))
return user;
return null;
}