Use new C# features for serializable files

This commit is contained in:
Łukasz Domeradzki
2025-08-13 22:15:41 +02:00
parent 2b43cec8fe
commit ff2a2a728d
5 changed files with 100 additions and 117 deletions

View File

@@ -41,54 +41,51 @@ internal sealed class BotCache : SerializableFile {
[JsonObjectCreationHandling(JsonObjectCreationHandling.Populate)]
internal ConcurrentList<AssetForListing> LastAnnouncedAssetsForListing { get; private init; } = [];
[JsonInclude]
[JsonPropertyName("BackingLastAnnouncedTradeToken")]
internal string? LastAnnouncedTradeToken {
get => BackingLastAnnouncedTradeToken;
get;
set {
if (BackingLastAnnouncedTradeToken == value) {
if (field == value) {
return;
}
BackingLastAnnouncedTradeToken = value;
field = value;
Utilities.InBackground(Save);
}
}
[JsonInclude]
[JsonPropertyName("BackingLastInventoryChecksumBeforeDeduplication")]
internal string? LastInventoryChecksumBeforeDeduplication {
get => BackingLastInventoryChecksumBeforeDeduplication;
get;
set {
if (BackingLastInventoryChecksumBeforeDeduplication == value) {
if (field == value) {
return;
}
BackingLastInventoryChecksumBeforeDeduplication = value;
field = value;
Utilities.InBackground(Save);
}
}
[JsonInclude]
[JsonPropertyName("BackingLastRequestAt")]
internal DateTime? LastRequestAt {
get => BackingLastRequestAt;
get;
set {
if (BackingLastRequestAt == value) {
if (field == value) {
return;
}
BackingLastRequestAt = value;
field = value;
Utilities.InBackground(Save);
}
}
[JsonInclude]
private string? BackingLastAnnouncedTradeToken { get; set; }
[JsonInclude]
private string? BackingLastInventoryChecksumBeforeDeduplication { get; set; }
[JsonInclude]
private DateTime? BackingLastRequestAt { get; set; }
private BotCache(string filePath) : this() {
ArgumentException.ThrowIfNullOrEmpty(filePath);
@@ -98,18 +95,18 @@ internal sealed class BotCache : SerializableFile {
[JsonConstructor]
private BotCache() => LastAnnouncedAssetsForListing.OnModified += OnObjectModified;
[UsedImplicitly]
public bool ShouldSerializeBackingLastAnnouncedTradeToken() => !string.IsNullOrEmpty(BackingLastAnnouncedTradeToken);
[UsedImplicitly]
public bool ShouldSerializeBackingLastInventoryChecksumBeforeDeduplication() => !string.IsNullOrEmpty(BackingLastInventoryChecksumBeforeDeduplication);
[UsedImplicitly]
public bool ShouldSerializeBackingLastRequestAt() => BackingLastRequestAt.HasValue;
[UsedImplicitly]
public bool ShouldSerializeLastAnnouncedAssetsForListing() => LastAnnouncedAssetsForListing.Count > 0;
[UsedImplicitly]
public bool ShouldSerializeLastAnnouncedTradeToken() => !string.IsNullOrEmpty(LastAnnouncedTradeToken);
[UsedImplicitly]
public bool ShouldSerializeLastInventoryChecksumBeforeDeduplication() => !string.IsNullOrEmpty(LastInventoryChecksumBeforeDeduplication);
[UsedImplicitly]
public bool ShouldSerializeLastRequestAt() => LastRequestAt.HasValue;
protected override void Dispose(bool disposing) {
if (disposing) {
// Events we registered