diff --git a/DisCatSharp/Net/Rest/RestClient.cs b/DisCatSharp/Net/Rest/RestClient.cs index d97d76f9e..2828eaf7c 100644 --- a/DisCatSharp/Net/Rest/RestClient.cs +++ b/DisCatSharp/Net/Rest/RestClient.cs @@ -526,8 +526,7 @@ private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket? var response = new RestResponse(); try { - if (this._disposed) - return; + ObjectDisposedException.ThrowIf(this._disposed, this); res = await this.HttpClient.SendAsync(req, HttpCompletionOption.ResponseContentRead, CancellationToken.None).ConfigureAwait(false); diff --git a/DisCatSharp/Net/Rest/RestResponse.cs b/DisCatSharp/Net/Rest/RestResponse.cs index 89ccc34aa..b94ba67b7 100644 --- a/DisCatSharp/Net/Rest/RestResponse.cs +++ b/DisCatSharp/Net/Rest/RestResponse.cs @@ -21,7 +21,7 @@ public sealed class RestResponse /// /// Gets the contents of the response sent by the remote party. /// - public string Response { get; internal set; } = null!; + public string Response { get; internal set; } /// /// Initializes a new instance of the class. diff --git a/DisCatSharp/Net/Serialization/DiscordJson.cs b/DisCatSharp/Net/Serialization/DiscordJson.cs index c98c6ec07..24d674a26 100644 --- a/DisCatSharp/Net/Serialization/DiscordJson.cs +++ b/DisCatSharp/Net/Serialization/DiscordJson.cs @@ -41,7 +41,7 @@ public static string SerializeObject(object value) /// The type /// The received json. /// The discord client. - public static T DeserializeObject(string json, BaseDiscordClient? discord) where T : ObservableApiObject + public static T DeserializeObject(string? json, BaseDiscordClient? discord) where T : ObservableApiObject => DeserializeObjectInternal(json, discord); /// @@ -50,7 +50,7 @@ public static T DeserializeObject(string json, BaseDiscordClient? discord) wh /// The enumerable type. /// The received json. /// The discord client. - public static T DeserializeIEnumerableObject(string json, BaseDiscordClient? discord) where T : IEnumerable + public static T DeserializeIEnumerableObject(string? json, BaseDiscordClient? discord) where T : IEnumerable => DeserializeIEnumerableObjectInternal(json, discord); /// Populates an object with the values from a JSON node. @@ -95,8 +95,11 @@ private static string SerializeObjectInternal(object value, Type type, JsonSeria /// The type /// The received json. /// The discord client. - private static T DeserializeObjectInternal(string json, BaseDiscordClient? discord) where T : ObservableApiObject + private static T DeserializeObjectInternal(string? json, BaseDiscordClient? discord) where T : ObservableApiObject { + if (string.IsNullOrEmpty(json)) + return default; + var obj = JsonConvert.DeserializeObject(json, new JsonSerializerSettings() { ContractResolver = new OptionalJsonContractResolver() @@ -168,8 +171,11 @@ private static T DeserializeObjectInternal(string json, BaseDiscordClient? di /// The enumerable type. /// The received json. /// The discord client. - private static T DeserializeIEnumerableObjectInternal(string json, BaseDiscordClient? discord) where T : IEnumerable + private static T DeserializeIEnumerableObjectInternal(string? json, BaseDiscordClient? discord) where T : IEnumerable { + if (string.IsNullOrEmpty(json)) + return default; + var obj = JsonConvert.DeserializeObject(json, new JsonSerializerSettings() { ContractResolver = new OptionalJsonContractResolver()