Added playlist repository logic.

This commit is contained in:
2025-02-18 20:49:04 -05:00
parent 8cf4bb2804
commit 2bafd474a0
7 changed files with 182 additions and 6 deletions

View File

@@ -0,0 +1,26 @@
using System.Text.Json.Serialization;
using System.Text.Json;
namespace Harmonia.Core.Data;
public abstract class JsonFileRepository<TObject> : FileRepository<TObject> where TObject : notnull, new()
{
private readonly JsonSerializerOptions _options = new()
{
WriteIndented = true,
IgnoreReadOnlyProperties = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
protected override string Extension => "json";
protected override TObject Deserialize(Stream stream)
{
return JsonSerializer.Deserialize<TObject>(stream) ?? new();
}
protected override string Serialize(TObject obj)
{
return JsonSerializer.Serialize(obj, _options);
}
}