-
Notifications
You must be signed in to change notification settings - Fork 809
Expand file tree
/
Copy pathSerializableComponent.cs
More file actions
51 lines (44 loc) · 1.53 KB
/
SerializableComponent.cs
File metadata and controls
51 lines (44 loc) · 1.53 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.Text.Json;
using System.Text.Json.Nodes;
using UniGetUI.Core.Data;
namespace UniGetUI.PackageEngine.Serializable;
public abstract class SerializableComponent<T> where T: class
{
/// <summary>
/// Creates a deep copy of the object
/// </summary>
/// <returns>A memory-independend copy of this</returns>
public abstract T Copy();
/// <summary>
/// Loads data for this object from a JsonNode object
/// </summary>
/// <param name="data">The JSON from which to load the data</param>
public abstract void LoadFromJson(JsonNode data);
/// <summary>
/// Serializes this object into a JsonNode object
/// </summary>
/// <returns>A pretty-formatted JSON string representing the current data</returns>
public string AsJsonString()
{
return JsonSerializer.Serialize(AsJsonNode(), SerializationHelpers.DefaultOptions);
}
/// <summary>
/// Serializes this object into a JsonNode object
/// </summary>
/// <returns>A pretty-formatted JSON string representing the current data</returns>
public abstract JsonNode AsJsonNode();
/// <summary>
/// Creates an instance of this object with the default data
/// </summary>
public SerializableComponent()
{
}
/// <summary>
/// Creates an instance of this object, and loads the data from the given JsonNode object
/// </summary>
/// <param name="data">The JSON from which to load the data</param>
public SerializableComponent(JsonNode data)
{
LoadFromJson(data);
}
}