- Made the project compatible with C# 7.3

dev-rework
VollRagm 4 years ago
parent 7b353f428c
commit 8b73390e57

@ -56,7 +56,7 @@ namespace Discord.Net
public static BucketId Create(string httpMethod, string endpoint, Dictionary<string, string> majorParams) public static BucketId Create(string httpMethod, string endpoint, Dictionary<string, string> majorParams)
{ {
Preconditions.NotNullOrWhitespace(endpoint, nameof(endpoint)); Preconditions.NotNullOrWhitespace(endpoint, nameof(endpoint));
majorParams ??= new Dictionary<string, string>(); majorParams = majorParams ?? new Dictionary<string, string>();
return new BucketId(httpMethod, endpoint, majorParams, null); return new BucketId(httpMethod, endpoint, majorParams, null);
} }

@ -11,23 +11,23 @@ namespace Discord
/// <summary> /// <summary>
/// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare users. /// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare users.
/// </summary> /// </summary>
public static IEqualityComparer<IUser> UserComparer => _userComparer ??= new EntityEqualityComparer<IUser, ulong>(); public static IEqualityComparer<IUser> UserComparer => _userComparer =_userComparer ?? new EntityEqualityComparer<IUser, ulong>();
/// <summary> /// <summary>
/// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare guilds. /// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare guilds.
/// </summary> /// </summary>
public static IEqualityComparer<IGuild> GuildComparer => _guildComparer ??= new EntityEqualityComparer<IGuild, ulong>(); public static IEqualityComparer<IGuild> GuildComparer => _guildComparer = _guildComparer ?? new EntityEqualityComparer<IGuild, ulong>();
/// <summary> /// <summary>
/// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare channels. /// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare channels.
/// </summary> /// </summary>
public static IEqualityComparer<IChannel> ChannelComparer => _channelComparer ??= new EntityEqualityComparer<IChannel, ulong>(); public static IEqualityComparer<IChannel> ChannelComparer => _channelComparer = _channelComparer ?? new EntityEqualityComparer<IChannel, ulong>();
/// <summary> /// <summary>
/// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare roles. /// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare roles.
/// </summary> /// </summary>
public static IEqualityComparer<IRole> RoleComparer => _roleComparer ??= new EntityEqualityComparer<IRole, ulong>(); public static IEqualityComparer<IRole> RoleComparer => _roleComparer = _roleComparer ?? new EntityEqualityComparer<IRole, ulong>();
/// <summary> /// <summary>
/// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare messages. /// Gets an <see cref="IEqualityComparer{T}"/> to be used to compare messages.
/// </summary> /// </summary>
public static IEqualityComparer<IMessage> MessageComparer => _messageComparer ??= new EntityEqualityComparer<IMessage, ulong>(); public static IEqualityComparer<IMessage> MessageComparer => _messageComparer = _messageComparer ?? new EntityEqualityComparer<IMessage, ulong>();
private static IEqualityComparer<IUser> _userComparer; private static IEqualityComparer<IUser> _userComparer;
private static IEqualityComparer<IGuild> _guildComparer; private static IEqualityComparer<IGuild> _guildComparer;
@ -41,13 +41,11 @@ namespace Discord
{ {
public override bool Equals(TEntity x, TEntity y) public override bool Equals(TEntity x, TEntity y)
{ {
return (x, y) switch if (x == null && y == null) return true;
{ if (x == null && y != null) return false;
(null, null) => true, if (x != null && y == null) return false;
(null, _) => false, var tuple = new Tuple<TEntity, TEntity>(x, y);
(_, null) => false, return tuple.Item1.Id.Equals(tuple.Item2.Id);
var (l, r) => l.Id.Equals(r.Id)
};
} }
public override int GetHashCode(TEntity obj) public override int GetHashCode(TEntity obj)

@ -80,13 +80,17 @@ namespace Discord.API
/// <exception cref="ArgumentException">Unknown OAuth token type.</exception> /// <exception cref="ArgumentException">Unknown OAuth token type.</exception>
internal static string GetPrefixedToken(TokenType tokenType, string token) internal static string GetPrefixedToken(TokenType tokenType, string token)
{ {
return tokenType switch switch (tokenType)
{ {
default(TokenType) => token, case default(TokenType):
TokenType.Bot => $"Bot {token}", return token;
TokenType.Bearer => $"Bearer {token}", case TokenType.Bot:
_ => throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType)), 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) internal virtual void Dispose(bool disposing)
{ {
@ -1517,7 +1521,7 @@ namespace Discord.API
} }
private static BucketId GetBucketId(string httpMethod, BucketIds ids, Expression<Func<string>> endpointExpr, string callingMethod) private static BucketId GetBucketId(string httpMethod, BucketIds ids, Expression<Func<string>> endpointExpr, string callingMethod)
{ {
ids.HttpMethod ??= httpMethod; ids.HttpMethod = ids.HttpMethod ?? httpMethod;
return _bucketIdGenerators.GetOrAdd(callingMethod, x => CreateBucketId(endpointExpr))(ids); return _bucketIdGenerators.GetOrAdd(callingMethod, x => CreateBucketId(endpointExpr))(ids);
} }

@ -580,7 +580,7 @@ namespace Discord.WebSocket
return; return;
if (BaseConfig.AlwaysDownloadUsers) 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 TimedInvokeAsync(_readyEvent, nameof(Ready)).ConfigureAwait(false);
await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false); await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false);

Loading…
Cancel
Save