From 0ae03c7cd52e4d155a954ac9d04780e788ef1ee0 Mon Sep 17 00:00:00 2001 From: Archi Date: Tue, 14 Nov 2023 20:21:02 +0100 Subject: [PATCH] Syntax improvements --- ArchiSteamFarm/Core/ASF.cs | 2 +- ArchiSteamFarm/Helpers/SerializableFile.cs | 9 ++------- ArchiSteamFarm/IPC/Responses/ASFResponse.cs | 6 +----- ArchiSteamFarm/Steam/Cards/Game.cs | 10 +++++++--- ArchiSteamFarm/Steam/Storage/BotDatabase.cs | 6 +++++- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/ArchiSteamFarm/Core/ASF.cs b/ArchiSteamFarm/Core/ASF.cs index 00fedf570..0613b1203 100644 --- a/ArchiSteamFarm/Core/ASF.cs +++ b/ArchiSteamFarm/Core/ASF.cs @@ -102,7 +102,7 @@ public static class ASF { return fileType switch { EFileType.Config => Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName), EFileType.Database => Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName), - _ => throw new ArgumentOutOfRangeException(nameof(fileType)) + _ => throw new InvalidOperationException(nameof(fileType)) }; } diff --git a/ArchiSteamFarm/Helpers/SerializableFile.cs b/ArchiSteamFarm/Helpers/SerializableFile.cs index 8ae18a42b..d70a6d338 100644 --- a/ArchiSteamFarm/Helpers/SerializableFile.cs +++ b/ArchiSteamFarm/Helpers/SerializableFile.cs @@ -129,13 +129,8 @@ public abstract class SerializableFile : IDisposable { } internal static async Task Write(string filePath, string json) { - if (string.IsNullOrEmpty(filePath)) { - throw new ArgumentNullException(nameof(filePath)); - } - - if (string.IsNullOrEmpty(json)) { - throw new ArgumentNullException(nameof(json)); - } + ArgumentException.ThrowIfNullOrEmpty(filePath); + ArgumentException.ThrowIfNullOrEmpty(json); string newFilePath = $"{filePath}.new"; diff --git a/ArchiSteamFarm/IPC/Responses/ASFResponse.cs b/ArchiSteamFarm/IPC/Responses/ASFResponse.cs index 99f7e4d69..44f72f7a9 100644 --- a/ArchiSteamFarm/IPC/Responses/ASFResponse.cs +++ b/ArchiSteamFarm/IPC/Responses/ASFResponse.cs @@ -80,11 +80,7 @@ public sealed class ASFResponse { ArgumentException.ThrowIfNullOrEmpty(buildVariant); ArgumentNullException.ThrowIfNull(globalConfig); ArgumentOutOfRangeException.ThrowIfZero(memoryUsage); - - // TODO: Use this instead once we get rid of generic-netf - //ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(processStartTime, DateTime.UnixEpoch); - ArgumentOutOfRangeException.ThrowIfEqual(processStartTime, DateTime.MinValue); - + ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(processStartTime, DateTime.UnixEpoch); ArgumentNullException.ThrowIfNull(version); BuildVariant = buildVariant; diff --git a/ArchiSteamFarm/Steam/Cards/Game.cs b/ArchiSteamFarm/Steam/Cards/Game.cs index ec0e680b4..1a869b692 100644 --- a/ArchiSteamFarm/Steam/Cards/Game.cs +++ b/ArchiSteamFarm/Steam/Cards/Game.cs @@ -42,9 +42,13 @@ public sealed class Game : IEquatable { internal uint PlayableAppID { get; set; } internal Game(uint appID, string gameName, float hoursPlayed, ushort cardsRemaining, byte badgeLevel) { - AppID = appID > 0 ? appID : throw new ArgumentOutOfRangeException(nameof(appID)); - GameName = !string.IsNullOrEmpty(gameName) ? gameName : throw new ArgumentNullException(nameof(gameName)); - HoursPlayed = hoursPlayed >= 0 ? hoursPlayed : throw new ArgumentOutOfRangeException(nameof(hoursPlayed)); + ArgumentOutOfRangeException.ThrowIfZero(appID); + ArgumentException.ThrowIfNullOrEmpty(gameName); + ArgumentOutOfRangeException.ThrowIfNegative(hoursPlayed); + + AppID = appID; + GameName = gameName; + HoursPlayed = hoursPlayed; CardsRemaining = cardsRemaining; BadgeLevel = badgeLevel; diff --git a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs index f03e643dd..0e2eacaf5 100644 --- a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs +++ b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs @@ -132,7 +132,11 @@ public sealed class BotDatabase : GenericDatabase { [JsonProperty] private string? BackingSteamGuardData; - private BotDatabase(string filePath) : this() => FilePath = !string.IsNullOrEmpty(filePath) ? filePath : throw new ArgumentNullException(nameof(filePath)); + private BotDatabase(string filePath) : this() { + ArgumentException.ThrowIfNullOrEmpty(filePath); + + FilePath = filePath; + } [JsonConstructor] private BotDatabase() {