-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONHandler.cs
More file actions
26 lines (23 loc) · 768 Bytes
/
JSONHandler.cs
File metadata and controls
26 lines (23 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Text.Json;
namespace CodeLineCounter.Utils
{
public static class JsonHandler
{
private static readonly JsonSerializerOptions _options = new()
{
WriteIndented = true,
PropertyNameCaseInsensitive = true
};
public static void Serialize<T>(IEnumerable<T> data, string filePath)
{
string jsonString = JsonSerializer.Serialize(data, _options);
File.WriteAllText(filePath, jsonString);
}
public static IEnumerable<T> Deserialize<T>(string filePath)
{
string jsonString = File.ReadAllText(filePath);
return JsonSerializer.Deserialize<IEnumerable<T>>(jsonString, _options)
?? [];
}
}
}