From 8b73390e57442b6cd075804ea88251e3c25624b9 Mon Sep 17 00:00:00 2001 From: VollRahm Date: Thu, 5 Nov 2020 01:29:30 +0100 Subject: [PATCH] - Made the project compatible with C# 7.3 --- Discord.NET/Discord.Net.Core/Net/BucketId.cs | 2 +- .../Discord.Net.Core/Utils/Comparers.cs | 22 +++++++++---------- .../Discord.Net.Rest/DiscordRestApiClient.cs | 18 +++++++++------ .../DiscordSocketClient.cs | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Discord.NET/Discord.Net.Core/Net/BucketId.cs b/Discord.NET/Discord.Net.Core/Net/BucketId.cs index 96281a0..eafe143 100644 --- a/Discord.NET/Discord.Net.Core/Net/BucketId.cs +++ b/Discord.NET/Discord.Net.Core/Net/BucketId.cs @@ -56,7 +56,7 @@ namespace Discord.Net public static BucketId Create(string httpMethod, string endpoint, Dictionary majorParams) { Preconditions.NotNullOrWhitespace(endpoint, nameof(endpoint)); - majorParams ??= new Dictionary(); + majorParams = majorParams ?? new Dictionary(); return new BucketId(httpMethod, endpoint, majorParams, null); } diff --git a/Discord.NET/Discord.Net.Core/Utils/Comparers.cs b/Discord.NET/Discord.Net.Core/Utils/Comparers.cs index 3c7b8aa..6068121 100644 --- a/Discord.NET/Discord.Net.Core/Utils/Comparers.cs +++ b/Discord.NET/Discord.Net.Core/Utils/Comparers.cs @@ -11,23 +11,23 @@ namespace Discord /// /// Gets an to be used to compare users. /// - public static IEqualityComparer UserComparer => _userComparer ??= new EntityEqualityComparer(); + public static IEqualityComparer UserComparer => _userComparer =_userComparer ?? new EntityEqualityComparer(); /// /// Gets an to be used to compare guilds. /// - public static IEqualityComparer GuildComparer => _guildComparer ??= new EntityEqualityComparer(); + public static IEqualityComparer GuildComparer => _guildComparer = _guildComparer ?? new EntityEqualityComparer(); /// /// Gets an to be used to compare channels. /// - public static IEqualityComparer ChannelComparer => _channelComparer ??= new EntityEqualityComparer(); + public static IEqualityComparer ChannelComparer => _channelComparer = _channelComparer ?? new EntityEqualityComparer(); /// /// Gets an to be used to compare roles. /// - public static IEqualityComparer RoleComparer => _roleComparer ??= new EntityEqualityComparer(); + public static IEqualityComparer RoleComparer => _roleComparer = _roleComparer ?? new EntityEqualityComparer(); /// /// Gets an to be used to compare messages. /// - public static IEqualityComparer MessageComparer => _messageComparer ??= new EntityEqualityComparer(); + public static IEqualityComparer MessageComparer => _messageComparer = _messageComparer ?? new EntityEqualityComparer(); private static IEqualityComparer _userComparer; private static IEqualityComparer _guildComparer; @@ -41,13 +41,11 @@ namespace Discord { public override bool Equals(TEntity x, TEntity y) { - return (x, y) switch - { - (null, null) => true, - (null, _) => false, - (_, null) => false, - var (l, r) => l.Id.Equals(r.Id) - }; + if (x == null && y == null) return true; + if (x == null && y != null) return false; + if (x != null && y == null) return false; + var tuple = new Tuple(x, y); + return tuple.Item1.Id.Equals(tuple.Item2.Id); } public override int GetHashCode(TEntity obj) diff --git a/Discord.NET/Discord.Net.Rest/DiscordRestApiClient.cs b/Discord.NET/Discord.Net.Rest/DiscordRestApiClient.cs index 83aa6c7..e4d17e6 100644 --- a/Discord.NET/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/Discord.NET/Discord.Net.Rest/DiscordRestApiClient.cs @@ -80,13 +80,17 @@ namespace Discord.API /// Unknown OAuth token type. internal static string GetPrefixedToken(TokenType tokenType, string token) { - return tokenType switch + switch (tokenType) { - default(TokenType) => token, - TokenType.Bot => $"Bot {token}", - TokenType.Bearer => $"Bearer {token}", - _ => throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType)), - }; + case default(TokenType): + return token; + case TokenType.Bot: + return $"Bot {token}"; + case TokenType.Bearer: + return $"Bearer {token}"; + default: + throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType)); + } } internal virtual void Dispose(bool disposing) { @@ -1517,7 +1521,7 @@ namespace Discord.API } private static BucketId GetBucketId(string httpMethod, BucketIds ids, Expression> endpointExpr, string callingMethod) { - ids.HttpMethod ??= httpMethod; + ids.HttpMethod = ids.HttpMethod ?? httpMethod; return _bucketIdGenerators.GetOrAdd(callingMethod, x => CreateBucketId(endpointExpr))(ids); } diff --git a/Discord.NET/Discord.Net.WebSocket/DiscordSocketClient.cs b/Discord.NET/Discord.Net.WebSocket/DiscordSocketClient.cs index 0263f96..a75d8e5 100644 --- a/Discord.NET/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/Discord.NET/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -580,7 +580,7 @@ namespace Discord.WebSocket return; if (BaseConfig.AlwaysDownloadUsers) - _ = DownloadUsersAsync(Guilds.Where(x => x.IsAvailable && !x.HasAllMembers)); + _ = DownloadUsersAsync(Guilds.Where(x1 => x1.IsAvailable && !x1.HasAllMembers)); await TimedInvokeAsync(_readyEvent, nameof(Ready)).ConfigureAwait(false); await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false);