JSON export added
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.Utils;
|
||||
|
||||
public static class DataSerialization
|
||||
{
|
||||
private static void SaveData(string path, string data)
|
||||
{
|
||||
System.IO.File.WriteAllText(path, data);
|
||||
}
|
||||
|
||||
private static string LoadData(string path)
|
||||
{
|
||||
return System.IO.File.ReadAllText(path);
|
||||
}
|
||||
|
||||
public static void SavePoint(Point point, string path)
|
||||
{
|
||||
SaveData(path, point.Serialize());
|
||||
}
|
||||
|
||||
public static Point? LoadPoint(string path)
|
||||
{
|
||||
return Deserialization.Deserialize(LoadData(path));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Serialization
|
||||
{
|
||||
public static string Serialize(this Point point)
|
||||
{
|
||||
return JsonSerializer.Serialize(point);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Deserialization
|
||||
{
|
||||
public static Point? Deserialize(string point)
|
||||
{
|
||||
try
|
||||
{
|
||||
return string.IsNullOrEmpty(point) ? JsonSerializer.Deserialize<Point>(point) : null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ArgumentException("Ошибка расшивроки json файла");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user