From 0394f470c98e62c4b376860b255ab4fcc835f0ea Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 6 Feb 2025 22:29:17 +0000 Subject: [PATCH] Improved `JsonUtil` comments --- Libraries/Core/Utils/JsonUtil.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Libraries/Core/Utils/JsonUtil.cs b/Libraries/Core/Utils/JsonUtil.cs index 85121394..9f1c6be0 100644 --- a/Libraries/Core/Utils/JsonUtil.cs +++ b/Libraries/Core/Utils/JsonUtil.cs @@ -60,21 +60,47 @@ public class JsonUtil }; + /// + /// Convert JSON into an object + /// + /// The type of the object to deserialize to + /// The JSON string to deserialize + /// Deserialized object or null public T? Deserialize(string? json) { return string.IsNullOrEmpty(json) ? default : JsonSerializer.Deserialize(json, jsonSerializerOptionsNoIndent); } + /// + /// Convert JSON into an object + /// + /// The JSON string to deserialize + /// The type of the object to deserialize to + /// public object? Deserialize(string? json, Type type) { return string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize(json, type, jsonSerializerOptionsNoIndent); } + /// + /// Convert an object into JSON + /// + /// Type of the object being serialised + /// Object to serialise + /// Should JSON be indented + /// Serialised object as JSON, or null public string? Serialize(T? obj, bool indented = false) { return obj == null ? null : JsonSerializer.Serialize(obj, indented ? jsonSerializerOptionsIndented : jsonSerializerOptionsNoIndent); } + /// + /// Convert an object into JSON + /// + /// Object to serialise + /// Type of object being serialsied + /// Should JSON be indented + /// public string? Serialize(object? obj, Type type, bool indented = false) { return obj == null ? null : JsonSerializer.Serialize(obj, type, indented ? jsonSerializerOptionsIndented : jsonSerializerOptionsNoIndent);