Files
WatchIt/WatchIt.Database/WatchIt.Database.Model/WatchIt.Database.Model.Seeding/DataReader.cs

23 lines
654 B
C#
Raw Normal View History

2024-04-27 22:36:16 +02:00
using System.Text.Json;
namespace WatchIt.Database.Model.Seeding;
public class DataReader
{
#region METHODS
public static IEnumerable<T> Read<T>() => Read<T>(typeof(T).Name);
public static IEnumerable<T> Read<T>(string filename)
{
string jsonFile = $@"..\..\WatchIt.Database\WatchIt.Database.Model\WatchIt.Database.Model.Seeding\Data\{filename}.json";
string dataString = File.ReadAllText(jsonFile);
IEnumerable<T>? data = JsonSerializer.Deserialize<IEnumerable<T>>(dataString);
if (data is null)
{
throw new JsonException();
}
return data;
}
#endregion
}