Added playlist repository logic.
This commit is contained in:
26
Harmonia.Core/Data/JsonFileRepository.cs
Normal file
26
Harmonia.Core/Data/JsonFileRepository.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user