Syntax improvements

This commit is contained in:
Archi
2023-11-14 20:21:02 +01:00
parent f2ff2f4929
commit 0ae03c7cd5
5 changed files with 16 additions and 17 deletions

View File

@@ -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))
};
}

View File

@@ -129,13 +129,8 @@ public abstract class SerializableFile : IDisposable {
}
internal static async Task<bool> 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";

View File

@@ -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;

View File

@@ -42,9 +42,13 @@ public sealed class Game : IEquatable<Game> {
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;

View File

@@ -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() {