Skip to content

Commit

Permalink
Added Load() method in JsonHelper (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Jul 29, 2023
1 parent 38937ee commit 5b9c8fb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions PeyrSharp.Core/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@ public static void SaveAsJson<T>(T obj, string fileName)
File.WriteAllText(fileName, json);
}

public static T LoadFromJson<T>(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<T>(json);

// Return the object
return obj;
}
}
}

0 comments on commit 5b9c8fb

Please sign in to comment.