public static object DeserializeObjectFromFile(string filePath) { if (!File.Exists(filePath)) { return(null); } EasySerializer.SetEnvironmentVariables(); Stream stream = null; try { stream = File.Open(filePath, FileMode.Open); } catch { return(null); } BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new VersionDeserializationBinder(); object o = formatter.Deserialize(stream); stream.Close(); return(o); }
public static object DeserializeObjectFromBytes(byte[] data) { EasySerializer.SetEnvironmentVariables(); MemoryStream stream = new MemoryStream(data); BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new VersionDeserializationBinder(); return(formatter.Deserialize(stream)); }
public static void SerializeObjectToFile(object serializableObject, string filePath) { EasySerializer.SetEnvironmentVariables(); Stream stream = File.Open(filePath, FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new VersionDeserializationBinder(); formatter.Serialize(stream, serializableObject); stream.Close(); }
public static byte[] SerializeObjectToBytes(object serializableObject) { EasySerializer.SetEnvironmentVariables(); MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new VersionDeserializationBinder(); formatter.Serialize(stream, serializableObject); return(stream.GetBuffer()); }
public static void SerializeObjectToFile(object serializableObject, string filePath) { EasySerializer.SetEnvironmentVariables(); Stream stream = null; try { stream = File.Open(filePath, FileMode.Create); } catch (FileNotFoundException e) { e.ToString(); return; } BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new VersionDeserializationBinder(); formatter.Serialize(stream, serializableObject); stream.Close(); }