public static void SaveJsonToFileRemoveOnNull <T>(this T data, string path, bool formatting = true) where T : class, IJsonSerializable { if (data == null) { FileWrapper.RemoveIfExists(path); } else { data.SaveToJsonFile(path, formatting); } }
public static bool LoadFromJsonFileIfExists <T>(string path, out T data, bool printError = true) where T : class, IJsonSerializable, new() { if (!FileWrapper.Exists(path)) { data = default; return(false); } else { return(LoadFromJsonFile(path, out data, printError)); } }
static FileStream OpenFileWrap(string path, FileMode mode, bool wrap) { return(wrap ? FileWrapper.Open(path, mode) : File.Open(path, mode)); }