Skip to content

Commit

Permalink
improve JSON mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Apr 10, 2024
1 parent ab0a040 commit 8c4d817
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace ProjBobcat.Class.Model.CurseForge;
Expand All @@ -20,7 +21,7 @@ public class CurseForgeAddonInfo
[JsonPropertyName("gameId")] public int GameId { get; set; }

[JsonPropertyName("summary")] public string? Summary { get; set; }
[JsonPropertyName("links")] public IReadOnlyDictionary<string, string> Links { get; set; } = new Dictionary<string, string>();
[JsonPropertyName("links")] public IReadOnlyDictionary<string, string> Links { get; set; } = ImmutableDictionary<string, string>.Empty;

[JsonPropertyName("defaultFileId")] public int DefaultFileId { get; set; }
[JsonPropertyName("releaseType")] public int ReleaseType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace ProjBobcat.Class.Model.Forge;
Expand Down Expand Up @@ -47,7 +48,7 @@ public class ForgeInstallProfile

[JsonPropertyName("data")]
public IReadOnlyDictionary<string, ForgeInstallProfileData> Data { get; set; } =
new Dictionary<string, ForgeInstallProfileData>();
ImmutableDictionary<string, ForgeInstallProfileData>.Empty;

[JsonPropertyName("processors")] public ForgeInstallProfileProcessor[] Processors { get; set; } = [];

Expand Down
7 changes: 3 additions & 4 deletions ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace ProjBobcat.Class.Model;
Expand All @@ -8,11 +9,9 @@ public class GameRules
[JsonPropertyName("action")] public required string Action { get; init; }

[JsonPropertyName("features")]
public IReadOnlyDictionary<string, bool> Features { get; set; } = new Dictionary<string, bool>();
public IReadOnlyDictionary<string, bool> Features { get; set; } = ImmutableDictionary<string, bool>.Empty;
}

[JsonSerializable(typeof(GameRules))]
[JsonSerializable(typeof(GameRules[]))]
partial class GameRulesContext : JsonSerializerContext
{
}
partial class GameRulesContext : JsonSerializerContext;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace ProjBobcat.Class.Model.Modrinth;
Expand All @@ -8,7 +9,7 @@ public class ModrinthModPackFileModel
[JsonPropertyName("path")] public string? Path { get; set; }

[JsonPropertyName("hashes")]
public IReadOnlyDictionary<string, string> Hashes { get; set; } = new Dictionary<string, string>();
public IReadOnlyDictionary<string, string> Hashes { get; set; } = ImmutableDictionary<string, string>.Empty;

[JsonPropertyName("downloads")] public string[] Downloads { get; set; } = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace ProjBobcat.Class.Model.Modrinth;
Expand All @@ -18,7 +19,7 @@ public class ModrinthModPackIndexModel
[JsonPropertyName("files")] public ModrinthModPackFileModel[] Files { get; set; } = [];

[JsonPropertyName("dependencies")]
public IReadOnlyDictionary<string, string> Dependencies { get; set; } = new Dictionary<string, string>();
public IReadOnlyDictionary<string, string> Dependencies { get; set; } = ImmutableDictionary<string, string>.Empty;
}

[JsonSerializable(typeof(ModrinthModPackIndexModel))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public class UserProfilePropertyValue
}

[JsonSerializable(typeof(UserProfilePropertyValue))]
public partial class UserProfilePropertyValueContext : JsonSerializerContext{}
public partial class UserProfilePropertyValueContext : JsonSerializerContext;
4 changes: 1 addition & 3 deletions ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,4 @@ public class RawVersionModel
}

[JsonSerializable(typeof(RawVersionModel))]
public partial class RawVersionModelContext : JsonSerializerContext
{
}
public partial class RawVersionModelContext : JsonSerializerContext;

0 comments on commit 8c4d817

Please sign in to comment.