Fix swapped parameters in ArgumentException, ArgumentNullException cstrs (#1139)

* Fix swapped parameters in ArgumentException and ArgumentNullException cstrs

The constructors of ArgumentException and ArgumentNullException are inconsistent with each other, which results in their parameters being swapped here and there.

* Use named parameters for ArgumentException constructors

Cleans up some of the methods of EmbedBuilder to use simpler syntax as well
This commit is contained in:
Chris Johnston
2018-09-06 19:08:45 -07:00
committed by Christopher F
parent 272604f275
commit 9e9a11d4b0
9 changed files with 56 additions and 74 deletions

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Globalization; using System.Globalization;
namespace Discord namespace Discord
@@ -58,7 +58,7 @@ namespace Discord
{ {
if (TryParse(text, out Emote result)) if (TryParse(text, out Emote result))
return result; return result;
throw new ArgumentException("Invalid emote format", nameof(text)); throw new ArgumentException(message: "Invalid emote format", paramName: nameof(text));
} }
public static bool TryParse(string text, out Emote result) public static bool TryParse(string text, out Emote result)

View File

@@ -29,7 +29,7 @@ namespace Discord
get => _title; get => _title;
set set
{ {
if (value?.Length > MaxTitleLength) throw new ArgumentException($"Title length must be less than or equal to {MaxTitleLength}.", nameof(Title)); if (value?.Length > MaxTitleLength) throw new ArgumentException(message: $"Title length must be less than or equal to {MaxTitleLength}.", paramName: nameof(Title));
_title = value; _title = value;
} }
} }
@@ -38,7 +38,7 @@ namespace Discord
get => _description; get => _description;
set set
{ {
if (value?.Length > MaxDescriptionLength) throw new ArgumentException($"Description length must be less than or equal to {MaxDescriptionLength}.", nameof(Description)); if (value?.Length > MaxDescriptionLength) throw new ArgumentException(message: $"Description length must be less than or equal to {MaxDescriptionLength}.", paramName: nameof(Description));
_description = value; _description = value;
} }
} }
@@ -48,7 +48,7 @@ namespace Discord
get => _url; get => _url;
set set
{ {
if (!value.IsNullOrUri()) throw new ArgumentException("Url must be a well-formed URI", nameof(Url)); if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI", paramName: nameof(Url));
_url = value; _url = value;
} }
} }
@@ -57,7 +57,7 @@ namespace Discord
get => _thumbnail?.Url; get => _thumbnail?.Url;
set set
{ {
if (!value.IsNullOrUri()) throw new ArgumentException("Url must be a well-formed URI", nameof(ThumbnailUrl)); if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI", paramName: nameof(ThumbnailUrl));
_thumbnail = new EmbedThumbnail(value, null, null, null); _thumbnail = new EmbedThumbnail(value, null, null, null);
} }
} }
@@ -66,7 +66,7 @@ namespace Discord
get => _image?.Url; get => _image?.Url;
set set
{ {
if (!value.IsNullOrUri()) throw new ArgumentException("Url must be a well-formed URI", nameof(ImageUrl)); if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI", paramName: nameof(ImageUrl));
_image = new EmbedImage(value, null, null, null); _image = new EmbedImage(value, null, null, null);
} }
} }
@@ -75,8 +75,8 @@ namespace Discord
get => _fields; get => _fields;
set set
{ {
if (value == null) throw new ArgumentNullException("Cannot set an embed builder's fields collection to null", nameof(Fields)); if (value == null) throw new ArgumentNullException(paramName: nameof(Fields), message: "Cannot set an embed builder's fields collection to null");
if (value.Count > MaxFieldCount) throw new ArgumentException($"Field count must be less than or equal to {MaxFieldCount}.", nameof(Fields)); if (value.Count > MaxFieldCount) throw new ArgumentException(message: $"Field count must be less than or equal to {MaxFieldCount}.", paramName: nameof(Fields));
_fields = value; _fields = value;
} }
} }
@@ -200,7 +200,7 @@ namespace Discord
{ {
if (Fields.Count >= MaxFieldCount) if (Fields.Count >= MaxFieldCount)
{ {
throw new ArgumentException($"Field count must be less than or equal to {MaxFieldCount}.", nameof(field)); throw new ArgumentException(message: $"Field count must be less than or equal to {MaxFieldCount}.", paramName: nameof(field));
} }
Fields.Add(field); Fields.Add(field);
@@ -239,8 +239,8 @@ namespace Discord
get => _name; get => _name;
set set
{ {
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Field name must not be null, empty or entirely whitespace.", nameof(Name)); if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(message: "Field name must not be null, empty or entirely whitespace.", paramName: nameof(Name));
if (value.Length > MaxFieldNameLength) throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name)); if (value.Length > MaxFieldNameLength) throw new ArgumentException(message: $"Field name length must be less than or equal to {MaxFieldNameLength}.", paramName: nameof(Name));
_name = value; _name = value;
} }
} }
@@ -251,8 +251,8 @@ namespace Discord
set set
{ {
var stringValue = value?.ToString(); var stringValue = value?.ToString();
if (string.IsNullOrEmpty(stringValue)) throw new ArgumentException("Field value must not be null or empty.", nameof(Value)); if (string.IsNullOrEmpty(stringValue)) throw new ArgumentException(message: "Field value must not be null or empty.", paramName: nameof(Value));
if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value)); if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException(message: $"Field value length must be less than or equal to {MaxFieldValueLength}.", paramName: nameof(Value));
_value = stringValue; _value = stringValue;
} }
} }
@@ -290,7 +290,7 @@ namespace Discord
get => _name; get => _name;
set set
{ {
if (value?.Length > MaxAuthorNameLength) throw new ArgumentException($"Author name length must be less than or equal to {MaxAuthorNameLength}.", nameof(Name)); if (value?.Length > MaxAuthorNameLength) throw new ArgumentException(message: $"Author name length must be less than or equal to {MaxAuthorNameLength}.", paramName: nameof(Name));
_name = value; _name = value;
} }
} }
@@ -299,7 +299,7 @@ namespace Discord
get => _url; get => _url;
set set
{ {
if (!value.IsNullOrUri()) throw new ArgumentException("Url must be a well-formed URI", nameof(Url)); if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI", paramName: nameof(Url));
_url = value; _url = value;
} }
} }
@@ -308,7 +308,7 @@ namespace Discord
get => _iconUrl; get => _iconUrl;
set set
{ {
if (!value.IsNullOrUri()) throw new ArgumentException("Url must be a well-formed URI", nameof(IconUrl)); if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI", paramName: nameof(IconUrl));
_iconUrl = value; _iconUrl = value;
} }
} }
@@ -345,7 +345,7 @@ namespace Discord
get => _text; get => _text;
set set
{ {
if (value?.Length > MaxFooterTextLength) throw new ArgumentException($"Footer text length must be less than or equal to {MaxFooterTextLength}.", nameof(Text)); if (value?.Length > MaxFooterTextLength) throw new ArgumentException(message: $"Footer text length must be less than or equal to {MaxFooterTextLength}.", paramName: nameof(Text));
_text = value; _text = value;
} }
} }
@@ -354,7 +354,7 @@ namespace Discord
get => _iconUrl; get => _iconUrl;
set set
{ {
if (!value.IsNullOrUri()) throw new ArgumentException("Url must be a well-formed URI", nameof(IconUrl)); if (!value.IsNullOrUri()) throw new ArgumentException(message: "Url must be a well-formed URI", paramName: nameof(IconUrl));
_iconUrl = value; _iconUrl = value;
} }
} }

View File

@@ -29,7 +29,7 @@ namespace Discord
case ICategoryChannel _: return Category; case ICategoryChannel _: return Category;
case IDMChannel _: return DM; case IDMChannel _: return DM;
case IGroupChannel _: return Group; case IGroupChannel _: return Group;
default: throw new ArgumentException("Unknown channel type", nameof(channel)); default: throw new ArgumentException(message: "Unknown channel type", paramName: nameof(channel));
} }
} }

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -160,23 +160,23 @@ namespace Discord
public ConcurrentHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer) public ConcurrentHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
: this(comparer) : this(comparer)
{ {
if (collection == null) throw new ArgumentNullException(nameof(collection)); if (collection == null) throw new ArgumentNullException(paramName: nameof(collection));
InitializeFromCollection(collection); InitializeFromCollection(collection);
} }
public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer) public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer)
: this(concurrencyLevel, DefaultCapacity, false, comparer) : this(concurrencyLevel, DefaultCapacity, false, comparer)
{ {
if (collection == null) throw new ArgumentNullException(nameof(collection)); if (collection == null) throw new ArgumentNullException(paramName: nameof(collection));
if (comparer == null) throw new ArgumentNullException(nameof(comparer)); if (comparer == null) throw new ArgumentNullException(paramName: nameof(comparer));
InitializeFromCollection(collection); InitializeFromCollection(collection);
} }
public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer) public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer)
: this(concurrencyLevel, capacity, false, comparer) { } : this(concurrencyLevel, capacity, false, comparer) { }
internal ConcurrentHashSet(int concurrencyLevel, int capacity, bool growLockArray, IEqualityComparer<T> comparer) internal ConcurrentHashSet(int concurrencyLevel, int capacity, bool growLockArray, IEqualityComparer<T> comparer)
{ {
if (concurrencyLevel < 1) throw new ArgumentOutOfRangeException(nameof(concurrencyLevel)); if (concurrencyLevel < 1) throw new ArgumentOutOfRangeException(paramName: nameof(concurrencyLevel));
if (capacity < 0) throw new ArgumentOutOfRangeException(nameof(capacity)); if (capacity < 0) throw new ArgumentOutOfRangeException(paramName: nameof(capacity));
if (comparer == null) throw new ArgumentNullException(nameof(comparer)); if (comparer == null) throw new ArgumentNullException(paramName: nameof(comparer));
if (capacity < concurrencyLevel) if (capacity < concurrencyLevel)
capacity = concurrencyLevel; capacity = concurrencyLevel;
@@ -197,7 +197,7 @@ namespace Discord
{ {
foreach (var value in collection) foreach (var value in collection)
{ {
if (value == null) throw new ArgumentNullException("key"); if (value == null) throw new ArgumentNullException(paramName: "key");
if (!TryAddInternal(value, _comparer.GetHashCode(value), false)) if (!TryAddInternal(value, _comparer.GetHashCode(value), false))
throw new ArgumentException(); throw new ArgumentException();
@@ -209,7 +209,7 @@ namespace Discord
public bool ContainsKey(T value) public bool ContainsKey(T value)
{ {
if (value == null) throw new ArgumentNullException("key"); if (value == null) throw new ArgumentNullException(paramName: "key");
return ContainsKeyInternal(value, _comparer.GetHashCode(value)); return ContainsKeyInternal(value, _comparer.GetHashCode(value));
} }
private bool ContainsKeyInternal(T value, int hashcode) private bool ContainsKeyInternal(T value, int hashcode)
@@ -232,7 +232,7 @@ namespace Discord
public bool TryAdd(T value) public bool TryAdd(T value)
{ {
if (value == null) throw new ArgumentNullException("key"); if (value == null) throw new ArgumentNullException(paramName: "key");
return TryAddInternal(value, _comparer.GetHashCode(value), true); return TryAddInternal(value, _comparer.GetHashCode(value), true);
} }
private bool TryAddInternal(T value, int hashcode, bool acquireLock) private bool TryAddInternal(T value, int hashcode, bool acquireLock)
@@ -281,7 +281,7 @@ namespace Discord
public bool TryRemove(T value) public bool TryRemove(T value)
{ {
if (value == null) throw new ArgumentNullException("key"); if (value == null) throw new ArgumentNullException(paramName: "key");
return TryRemoveInternal(value); return TryRemoveInternal(value);
} }
private bool TryRemoveInternal(T value) private bool TryRemoveInternal(T value)

View File

@@ -21,7 +21,7 @@ namespace Discord
{ {
if (TryParseUser(text, out ulong id)) if (TryParseUser(text, out ulong id))
return id; return id;
throw new ArgumentException("Invalid mention format", nameof(text)); throw new ArgumentException(message: "Invalid mention format", paramName: nameof(text));
} }
/// <summary> Tries to parse a provided user mention string. </summary> /// <summary> Tries to parse a provided user mention string. </summary>
public static bool TryParseUser(string text, out ulong userId) public static bool TryParseUser(string text, out ulong userId)
@@ -45,7 +45,7 @@ namespace Discord
{ {
if (TryParseChannel(text, out ulong id)) if (TryParseChannel(text, out ulong id))
return id; return id;
throw new ArgumentException("Invalid mention format", nameof(text)); throw new ArgumentException(message: "Invalid mention format", paramName: nameof(text));
} }
/// <summary>Tries to parse a provided channel mention string. </summary> /// <summary>Tries to parse a provided channel mention string. </summary>
public static bool TryParseChannel(string text, out ulong channelId) public static bool TryParseChannel(string text, out ulong channelId)
@@ -66,7 +66,7 @@ namespace Discord
{ {
if (TryParseRole(text, out ulong id)) if (TryParseRole(text, out ulong id))
return id; return id;
throw new ArgumentException("Invalid mention format", nameof(text)); throw new ArgumentException(message: "Invalid mention format", paramName: nameof(text));
} }
/// <summary>Tries to parse a provided role mention string. </summary> /// <summary>Tries to parse a provided role mention string. </summary>
public static bool TryParseRole(string text, out ulong roleId) public static bool TryParseRole(string text, out ulong roleId)

View File

@@ -10,8 +10,8 @@ namespace Discord
private static ArgumentNullException CreateNotNullException(string name, string msg) private static ArgumentNullException CreateNotNullException(string name, string msg)
{ {
if (msg == null) return new ArgumentNullException(name); if (msg == null) return new ArgumentNullException(paramName: name);
else return new ArgumentNullException(name, msg); else return new ArgumentNullException(paramName: name, message: msg);
} }
//Strings //Strings
@@ -45,10 +45,7 @@ namespace Discord
} }
private static ArgumentException CreateNotEmptyException(string name, string msg) private static ArgumentException CreateNotEmptyException(string name, string msg)
{ => new ArgumentException(message: msg ?? "Argument cannot be blank.", paramName: name);
if (msg == null) return new ArgumentException("Argument cannot be blank", name);
else return new ArgumentException(name, msg);
}
//Numerics //Numerics
public static void NotEqual(sbyte obj, sbyte value, string name, string msg = null) { if (obj == value) throw CreateNotEqualException(name, msg, value); } public static void NotEqual(sbyte obj, sbyte value, string name, string msg = null) { if (obj == value) throw CreateNotEqualException(name, msg, value); }
@@ -85,10 +82,7 @@ namespace Discord
public static void NotEqual(Optional<ulong?> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value == value) throw CreateNotEqualException(name, msg, value); } public static void NotEqual(Optional<ulong?> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value == value) throw CreateNotEqualException(name, msg, value); }
private static ArgumentException CreateNotEqualException<T>(string name, string msg, T value) private static ArgumentException CreateNotEqualException<T>(string name, string msg, T value)
{ => new ArgumentException(message: msg ?? $"Value may not be equal to {value}", paramName: name);
if (msg == null) return new ArgumentException($"Value may not be equal to {value}", name);
else return new ArgumentException(msg, name);
}
public static void AtLeast(sbyte obj, sbyte value, string name, string msg = null) { if (obj < value) throw CreateAtLeastException(name, msg, value); } public static void AtLeast(sbyte obj, sbyte value, string name, string msg = null) { if (obj < value) throw CreateAtLeastException(name, msg, value); }
public static void AtLeast(byte obj, byte value, string name, string msg = null) { if (obj < value) throw CreateAtLeastException(name, msg, value); } public static void AtLeast(byte obj, byte value, string name, string msg = null) { if (obj < value) throw CreateAtLeastException(name, msg, value); }
@@ -108,10 +102,7 @@ namespace Discord
public static void AtLeast(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value < value) throw CreateAtLeastException(name, msg, value); } public static void AtLeast(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value < value) throw CreateAtLeastException(name, msg, value); }
private static ArgumentException CreateAtLeastException<T>(string name, string msg, T value) private static ArgumentException CreateAtLeastException<T>(string name, string msg, T value)
{ => new ArgumentException(message: msg ?? $"Value must be at least {value}", paramName: name);
if (msg == null) return new ArgumentException($"Value must be at least {value}", name);
else return new ArgumentException(msg, name);
}
public static void GreaterThan(sbyte obj, sbyte value, string name, string msg = null) { if (obj <= value) throw CreateGreaterThanException(name, msg, value); } public static void GreaterThan(sbyte obj, sbyte value, string name, string msg = null) { if (obj <= value) throw CreateGreaterThanException(name, msg, value); }
public static void GreaterThan(byte obj, byte value, string name, string msg = null) { if (obj <= value) throw CreateGreaterThanException(name, msg, value); } public static void GreaterThan(byte obj, byte value, string name, string msg = null) { if (obj <= value) throw CreateGreaterThanException(name, msg, value); }
@@ -131,10 +122,7 @@ namespace Discord
public static void GreaterThan(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value <= value) throw CreateGreaterThanException(name, msg, value); } public static void GreaterThan(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value <= value) throw CreateGreaterThanException(name, msg, value); }
private static ArgumentException CreateGreaterThanException<T>(string name, string msg, T value) private static ArgumentException CreateGreaterThanException<T>(string name, string msg, T value)
{ => new ArgumentException(message: msg ?? $"Value must be greater than {value}", paramName: name);
if (msg == null) return new ArgumentException($"Value must be greater than {value}", name);
else return new ArgumentException(msg, name);
}
public static void AtMost(sbyte obj, sbyte value, string name, string msg = null) { if (obj > value) throw CreateAtMostException(name, msg, value); } public static void AtMost(sbyte obj, sbyte value, string name, string msg = null) { if (obj > value) throw CreateAtMostException(name, msg, value); }
public static void AtMost(byte obj, byte value, string name, string msg = null) { if (obj > value) throw CreateAtMostException(name, msg, value); } public static void AtMost(byte obj, byte value, string name, string msg = null) { if (obj > value) throw CreateAtMostException(name, msg, value); }
@@ -154,10 +142,7 @@ namespace Discord
public static void AtMost(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value > value) throw CreateAtMostException(name, msg, value); } public static void AtMost(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value > value) throw CreateAtMostException(name, msg, value); }
private static ArgumentException CreateAtMostException<T>(string name, string msg, T value) private static ArgumentException CreateAtMostException<T>(string name, string msg, T value)
{ => new ArgumentException(message: msg ?? $"Value must be at most {value}", paramName: name);
if (msg == null) return new ArgumentException($"Value must be at most {value}", name);
else return new ArgumentException(msg, name);
}
public static void LessThan(sbyte obj, sbyte value, string name, string msg = null) { if (obj >= value) throw CreateLessThanException(name, msg, value); } public static void LessThan(sbyte obj, sbyte value, string name, string msg = null) { if (obj >= value) throw CreateLessThanException(name, msg, value); }
public static void LessThan(byte obj, byte value, string name, string msg = null) { if (obj >= value) throw CreateLessThanException(name, msg, value); } public static void LessThan(byte obj, byte value, string name, string msg = null) { if (obj >= value) throw CreateLessThanException(name, msg, value); }
@@ -177,10 +162,7 @@ namespace Discord
public static void LessThan(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value >= value) throw CreateLessThanException(name, msg, value); } public static void LessThan(Optional<ulong> obj, ulong value, string name, string msg = null) { if (obj.IsSpecified && obj.Value >= value) throw CreateLessThanException(name, msg, value); }
private static ArgumentException CreateLessThanException<T>(string name, string msg, T value) private static ArgumentException CreateLessThanException<T>(string name, string msg, T value)
{ => new ArgumentException(message: msg ?? $"Value must be less than {value}", paramName: name);
if (msg == null) return new ArgumentException($"Value must be less than {value}", name);
else return new ArgumentException(msg, name);
}
// Bulk Delete // Bulk Delete
public static void YoungerThanTwoWeeks(ulong[] collection, string name) public static void YoungerThanTwoWeeks(ulong[] collection, string name)
@@ -198,7 +180,7 @@ namespace Discord
for (var i = 0; i < roles.Length; i++) for (var i = 0; i < roles.Length; i++)
{ {
if (roles[i] == guildId) if (roles[i] == guildId)
throw new ArgumentException("The everyone role cannot be assigned to a user", name); throw new ArgumentException(message: "The everyone role cannot be assigned to a user", paramName: name);
} }
} }
} }

View File

@@ -19,7 +19,7 @@ namespace Discord
{ {
// A Null or WhiteSpace token of any type is invalid. // A Null or WhiteSpace token of any type is invalid.
if (string.IsNullOrWhiteSpace(token)) if (string.IsNullOrWhiteSpace(token))
throw new ArgumentNullException("A token cannot be null, empty, or contain only whitespace.", nameof(token)); throw new ArgumentNullException(paramName: nameof(token), message: "A token cannot be null, empty, or contain only whitespace.");
switch (tokenType) switch (tokenType)
{ {
@@ -34,11 +34,11 @@ namespace Discord
// this value was determined by referencing examples in the discord documentation, and by comparing with // this value was determined by referencing examples in the discord documentation, and by comparing with
// pre-existing tokens // pre-existing tokens
if (token.Length < 59) if (token.Length < 59)
throw new ArgumentException("A Bot token must be at least 59 characters in length.", nameof(token)); throw new ArgumentException(message: "A Bot token must be at least 59 characters in length.", paramName: nameof(token));
break; break;
default: default:
// All unrecognized TokenTypes (including User tokens) are considered to be invalid. // All unrecognized TokenTypes (including User tokens) are considered to be invalid.
throw new ArgumentException("Unrecognized TokenType.", nameof(token)); throw new ArgumentException(message: "Unrecognized TokenType.", paramName: nameof(token));
} }
} }

View File

@@ -78,7 +78,7 @@ namespace Discord.API
case TokenType.Bearer: case TokenType.Bearer:
return $"Bearer {token}"; return $"Bearer {token}";
default: default:
throw new ArgumentException("Unknown OAuth token type", nameof(tokenType)); throw new ArgumentException(message: "Unknown OAuth token type", paramName: nameof(tokenType));
} }
} }
internal virtual void Dispose(bool disposing) internal virtual void Dispose(bool disposing)
@@ -473,7 +473,7 @@ namespace Discord.API
Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content));
if (args.Content?.Length > DiscordConfig.MaxMessageSize) if (args.Content?.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content));
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(channelId: channelId); var ids = new BucketIds(channelId: channelId);
@@ -490,7 +490,7 @@ namespace Discord.API
Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content));
if (args.Content?.Length > DiscordConfig.MaxMessageSize) if (args.Content?.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content));
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);
return await SendJsonAsync<Message>("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); return await SendJsonAsync<Message>("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);

View File

@@ -147,7 +147,7 @@ namespace Discord.Rest
public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client,
string name, RequestOptions options, Action<TextChannelProperties> func = null) string name, RequestOptions options, Action<TextChannelProperties> func = null)
{ {
if (name == null) throw new ArgumentNullException(nameof(name)); if (name == null) throw new ArgumentNullException(paramName: nameof(name));
var props = new TextChannelProperties(); var props = new TextChannelProperties();
func?.Invoke(props); func?.Invoke(props);
@@ -164,7 +164,7 @@ namespace Discord.Rest
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
string name, RequestOptions options, Action<VoiceChannelProperties> func = null) string name, RequestOptions options, Action<VoiceChannelProperties> func = null)
{ {
if (name == null) throw new ArgumentNullException(nameof(name)); if (name == null) throw new ArgumentNullException(paramName: nameof(name));
var props = new VoiceChannelProperties(); var props = new VoiceChannelProperties();
func?.Invoke(props); func?.Invoke(props);
@@ -181,7 +181,7 @@ namespace Discord.Rest
public static async Task<RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, public static async Task<RestCategoryChannel> CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client,
string name, RequestOptions options) string name, RequestOptions options)
{ {
if (name == null) throw new ArgumentNullException(nameof(name)); if (name == null) throw new ArgumentNullException(paramName: nameof(name));
var args = new CreateGuildChannelParams(name, ChannelType.Category); var args = new CreateGuildChannelParams(name, ChannelType.Category);
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
@@ -221,7 +221,7 @@ namespace Discord.Rest
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client, public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client,
string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
{ {
if (name == null) throw new ArgumentNullException(nameof(name)); if (name == null) throw new ArgumentNullException(paramName: nameof(name));
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false); var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false);
var role = RestRole.Create(client, guild, model); var role = RestRole.Create(client, guild, model);
@@ -356,7 +356,7 @@ namespace Discord.Rest
public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func, public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func,
RequestOptions options) RequestOptions options)
{ {
if (func == null) throw new ArgumentNullException(nameof(func)); if (func == null) throw new ArgumentNullException(paramName: nameof(func));
var props = new EmoteProperties(); var props = new EmoteProperties();
func(props); func(props);