-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIJsonFileService.cs
More file actions
51 lines (48 loc) · 2.77 KB
/
Copy pathIJsonFileService.cs
File metadata and controls
51 lines (48 loc) · 2.77 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;
namespace Nickvision.Desktop.Filesystem;
/// <summary>
/// An interface of a service for working with json files.
/// </summary>
public interface IJsonFileService
{
/// <summary>
/// The event for when json files are saved.
/// </summary>
event EventHandler<JsonFileSavedEventArgs>? Saved;
/// <summary>
/// Loads a json file and deserializes it into an object.
/// </summary>
/// <param name="jsonTypeInfo">The JsonTypeInfo for T, obtained from a source-generated JsonSerializerContext</param>
/// <param name="name">The name of the json file (without the .json extension)</param>
/// <typeparam name="T">The type of the object to deserialize to</typeparam>
/// <returns>A deserialized object from the json file if successful, else a default constructed object</returns>
T Load<T>(JsonTypeInfo<T> jsonTypeInfo, string? name = null) where T : new();
/// <summary>
/// Loads a json file and deserializes it into an object asynchronously.
/// </summary>
/// <param name="jsonTypeInfo">The JsonTypeInfo for T, obtained from a source-generated JsonSerializerContext</param>
/// <param name="name">The name of the json file (without the .json extension)</param>
/// <typeparam name="T">The type of the object to deserialize to</typeparam>
/// <returns>A deserialized object from the json file if successful, else a default constructed object</returns>
Task<T> LoadAsync<T>(JsonTypeInfo<T> jsonTypeInfo, string? name = null) where T : new();
/// <summary>
/// Saves an object by serializing it into a json file.
/// </summary>
/// <param name="obj">The object to serialize</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo for T, obtained from a source-generated JsonSerializerContext</param>
/// <param name="name">The name of the json file (without the .json extension)</param>
/// <typeparam name="T">The type of the object to serialize</typeparam>
/// <returns>True if the file was saved successfully, else false</returns>
bool Save<T>(T obj, JsonTypeInfo<T> jsonTypeInfo, string? name = null);
/// <summary>
/// Saves an object by serializing it into a json file asynchronously.
/// </summary>
/// <param name="obj">The object to serialize</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo for T, obtained from a source-generated JsonSerializerContext</param>
/// <param name="name">The name of the json file (without the .json extension)</param>
/// <typeparam name="T">The type of the object to serialize</typeparam>
/// <returns>True if the file was saved successfully, else false</returns>
Task<bool> SaveAsync<T>(T obj, JsonTypeInfo<T> jsonTypeInfo, string? name = null);
}