Round 2 of nullable checks

This commit is contained in:
JustArchi
2020-08-23 20:45:24 +02:00
parent f99043db30
commit b3d476dea4
34 changed files with 187 additions and 338 deletions

View File

@@ -31,9 +31,9 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog.Web;
#if !NETFRAMEWORK
using Microsoft.Extensions.Hosting;
#endif
namespace ArchiSteamFarm.IPC {

View File

@@ -220,7 +220,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
IOrderedDictionary validGamesToRedeemInBackground = Bot.ValidateGamesToRedeemInBackground(request.GamesToRedeemInBackground);
if ((validGamesToRedeemInBackground == null) || (validGamesToRedeemInBackground.Count == 0)) {
if (validGamesToRedeemInBackground.Count == 0) {
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(validGamesToRedeemInBackground))));
}

View File

@@ -57,16 +57,16 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(ASF.GlobalConfig.SteamOwnerID))));
}
Bot? targetBot = Bot.Bots.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
Bot? targetBot = Bot.Bots?.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
if (targetBot == null) {
return BadRequest(new GenericResponse(false, Strings.ErrorNoBotsDefined));
}
string command = request.Command!;
string? commandPrefix = ASF.GlobalConfig?.CommandPrefix ?? GlobalConfig.DefaultCommandPrefix;
string? commandPrefix = ASF.GlobalConfig != null ? ASF.GlobalConfig.CommandPrefix : GlobalConfig.DefaultCommandPrefix;
if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix, StringComparison.Ordinal)) {
if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix!, StringComparison.Ordinal)) {
command = command.Substring(commandPrefix!.Length);
if (string.IsNullOrEmpty(command)) {

View File

@@ -87,11 +87,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
underlyingType = enumType.GetUnifiedName();
foreach (object? value in Enum.GetValues(targetType)) {
if (value == null) {
continue;
}
string? valueText = value.ToString();
string? valueText = value?.ToString();
if (string.IsNullOrEmpty(valueText)) {
ASF.ArchiLogger.LogNullError(nameof(valueText));
@@ -105,7 +101,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
continue;
}
body[valueText] = valueObjText!;
body[valueText!] = valueObjText!;
}
}

View File

@@ -80,7 +80,7 @@ namespace ArchiSteamFarm.IPC.Integration {
throw new ArgumentNullException(nameof(context) + " || " + nameof(ClearFailedAuthorizationsTimer));
}
string? ipcPassword = ASF.GlobalConfig?.IPCPassword ?? GlobalConfig.DefaultIPCPassword;
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
if (string.IsNullOrEmpty(ipcPassword)) {
return HttpStatusCode.OK;

View File

@@ -31,9 +31,7 @@ namespace ArchiSteamFarm.IPC.Integration {
internal sealed class EnumSchemaFilter : ISchemaFilter {
public void Apply(OpenApiSchema schema, SchemaFilterContext context) {
if ((schema == null) || (context == null)) {
ASF.ArchiLogger.LogNullError(nameof(schema) + " || " + nameof(context));
return;
throw new ArgumentNullException(nameof(schema) + " || " + nameof(context));
}
if (!context.Type.IsEnum) {
@@ -74,7 +72,7 @@ namespace ArchiSteamFarm.IPC.Integration {
throw new ArgumentOutOfRangeException(nameof(enumValue));
}
definition.Add(enumName, enumObject);
definition.Add(enumName!, enumObject);
}
schema.AddExtension("x-definition", definition);

View File

@@ -19,6 +19,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
@@ -59,9 +60,7 @@ namespace ArchiSteamFarm.IPC.Requests {
public ImmutableHashSet<string> SAcceptedCreatorIDs {
set {
if (value == null) {
ASF.ArchiLogger.LogNullError(nameof(value));
return;
throw new ArgumentNullException(nameof(value));
}
HashSet<ulong> acceptedCreatorIDs = new HashSet<ulong>(value.Count);

View File

@@ -39,7 +39,6 @@ using Newtonsoft.Json.Serialization;
#if NETFRAMEWORK
using Newtonsoft.Json.Converters;
#endif
namespace ArchiSteamFarm.IPC {
@@ -92,7 +91,7 @@ namespace ArchiSteamFarm.IPC {
app.UseRouting();
#endif
string? ipcPassword = ASF.GlobalConfig?.IPCPassword ?? GlobalConfig.DefaultIPCPassword;
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
if (!string.IsNullOrEmpty(ipcPassword)) {
// We need ApiAuthenticationMiddleware for IPCPassword
@@ -137,7 +136,7 @@ namespace ArchiSteamFarm.IPC {
// Add support for response compression
services.AddResponseCompression();
string? ipcPassword = ASF.GlobalConfig?.IPCPassword ?? GlobalConfig.DefaultIPCPassword;
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
// Add CORS to allow userscripts and third-party apps
if (!string.IsNullOrEmpty(ipcPassword)) {