1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-13 00:28:10 -05:00

migrating to .NET Core 2.0

This commit is contained in:
RaidMax
2018-04-08 01:44:42 -05:00
parent 9eaed1d07d
commit e8b6525fea
121 changed files with 534 additions and 1157 deletions

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace SharedLibraryCore.Interfaces
{
interface ISerializable<T>
{
void Write();
}
public class Serialize<T> : ISerializable<T>
{
public static T Read(string filename)
{
try
{
string configText = File.ReadAllText(filename);
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(configText);
}
catch (Exception e)
{
throw new Exceptions.SerializeException($"Could not deserialize file {filename}: {e.Message}");
}
}
public void Write()
{
try
{
string configText = Newtonsoft.Json.JsonConvert.SerializeObject(this);
File.WriteAllText(Filename(), configText);
}
catch (Exception e)
{
throw new Exceptions.SerializeException($"Could not serialize file {Filename()}: {e.Message}");
}
}
public static void Write(string filename, T data)
{
try
{
string configText = Newtonsoft.Json.JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(filename, configText);
}
catch (Exception e)
{
throw new Exceptions.SerializeException($"Could not serialize file {filename}: {e.Message}");
}
}
public virtual string Filename() { return ToString(); }
}
}