internal static void Serialize <TObject>(TObject obj, string filePath) { try { FileFolderHelper.CheckAndCreateFile(filePath); var formatter = new BinaryFormatter(); using (var stream = new FileStream(filePath, FileMode.Create)) { formatter.Serialize(stream, obj); } } catch (Exception) { throw; } }
internal static void Serialize <T>(T obj, string filePath) { try { FileFolderHelper.CheckAndCreateFile(filePath); var formatter = new BinaryFormatter(); using (var stream = new FileStream(filePath, FileMode.Create)) { formatter.Serialize(stream, obj); } } catch (Exception ex) { Logger.Log($"Failed to serialize data to file {filePath}", ex); throw; } }
internal static TObject Deserialize <TObject>(string filePath) where TObject : class { try { FileFolderHelper.CheckAndCreateFile(filePath); var formatter = new BinaryFormatter(); using (var stream = new FileStream(filePath, FileMode.Open)) { return((TObject)formatter.Deserialize(stream)); } } catch (Exception ex) { Logger.Log($"Failed to Deserialize Data From File {filePath}", ex); return(null); } }
public static void Serialize <TObject>(TObject obj, string filePath) { try { FileFolderHelper.CheckAndCreateFile(filePath); var formatter = new BinaryFormatter(); using (var stream = new FileStream(filePath, FileMode.Create)) { formatter.Serialize(stream, obj); } } catch (Exception ex) { MessageBox.Show("SerializationFail" + ex.ToString()); Logger.Log($"Failed to serialize data to file {filePath}", ex); throw; } }