From 5b9c8fb89154ee89550d579e58277ef0db7b2dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Sat, 29 Jul 2023 10:18:52 +0200 Subject: [PATCH] Added Load() method in JsonHelper (#129) --- PeyrSharp.Core/JsonHelper.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/PeyrSharp.Core/JsonHelper.cs b/PeyrSharp.Core/JsonHelper.cs index d32f63c..675e13b 100644 --- a/PeyrSharp.Core/JsonHelper.cs +++ b/PeyrSharp.Core/JsonHelper.cs @@ -43,5 +43,16 @@ public static void SaveAsJson(T obj, string fileName) File.WriteAllText(fileName, json); } + public static T LoadFromJson(string fileName) + { + // Read the JSON string from the file + string json = File.ReadAllText(fileName); + + // Convert the JSON string to an object of type T + T obj = JsonSerializer.Deserialize(json); + + // Return the object + return obj; + } } }