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

@@ -60,8 +60,7 @@ namespace Discord.Rest
public RestUser GetUser(ulong id)
{
RestGroupUser user;
if (_users.TryGetValue(id, out user))
if (_users.TryGetValue(id, out RestGroupUser user))
return user;
return null;
}

View File

@@ -213,8 +213,7 @@ namespace Discord.Rest
//Roles
public RestRole GetRole(ulong id)
{
RestRole value;
if (_roles.TryGetValue(id, out value))
if (_roles.TryGetValue(id, out RestRole value))
return value;
return null;
}

View File

@@ -58,8 +58,7 @@ namespace Discord.Rest
{
if (Guild != null)
return Guild;
var guildChannel = Channel as IGuildChannel;
if (guildChannel != null)
if (Channel is IGuildChannel guildChannel)
return guildChannel.Guild; //If it fails, it'll still return this exception
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
}

View File

@@ -80,8 +80,7 @@ namespace Discord.Rest
if (endIndex == -1) break;
string content = text.Substring(index, endIndex - index + 1);
ulong id;
if (MentionUtils.TryParseUser(content, out id))
if (MentionUtils.TryParseUser(content, out ulong id))
{
IUser mentionedUser = null;
foreach (var mention in userMentions)

View File

@@ -19,8 +19,7 @@ namespace Discord.Net.Converters
if (property.Ignored)
return property;
var propInfo = member as PropertyInfo;
if (propInfo != null)
if (member is PropertyInfo propInfo)
{
var converter = GetConverter(property, propInfo, propInfo.PropertyType, 0);
if (converter != null)

View File

@@ -114,9 +114,8 @@ namespace Discord.Net.Queue
var now = DateTimeOffset.UtcNow;
foreach (var bucket in _buckets.Select(x => x.Value))
{
RequestBucket ignored;
if ((now - bucket.LastAttemptAt).TotalMinutes > 1.0)
_buckets.TryRemove(bucket.Id, out ignored);
_buckets.TryRemove(bucket.Id, out RequestBucket ignored);
}
await Task.Delay(60000, _cancelToken.Token); //Runs each minute
}

View File

@@ -14,9 +14,8 @@ namespace Discord.Net
internal RateLimitInfo(Dictionary<string, string> headers)
{
string temp;
IsGlobal = headers.TryGetValue("X-RateLimit-Global", out temp) &&
bool.TryParse(temp, out var isGlobal) ? isGlobal : false;
IsGlobal = headers.TryGetValue("X-RateLimit-Global", out string temp) &&
bool.TryParse(temp, out var isGlobal) ? isGlobal : false;
Limit = headers.TryGetValue("X-RateLimit-Limit", out temp) &&
int.TryParse(temp, out var limit) ? limit : (int?)null;
Remaining = headers.TryGetValue("X-RateLimit-Remaining", out temp) &&