/// <summary> /// Returns the object deserialized from the file specified, using a binary or text formatter. /// </summary> /// <param name="path">The path of the file the object is to be deserialized from.</param> /// <param name="binary">True to use a binary formatter, False to use a Soap one.</param> public static object PathDeserialize(this string path, bool binary) { path = path.Validated("Path"); using (FileStream sm = new FileStream(path, FileMode.Open)) { return(SerializationEx.Deserialize(sm, binary)); } }
/// <summary> /// Serializes the given object into the file specified, using a binary or text formatter. /// </summary> /// <param name="path">The path of the file the object will be persisted into.</param> /// <param name="obj">The object to serialize.</param> /// <param name="binary">True to use a binary formatter, False to use a Soap one.</param> public static void PathSerialize(this string path, object obj, bool binary) { path = path.Validated("Path"); if (obj == null) { throw new ArgumentNullException("obj", "Object cannot be null."); } using (FileStream sm = new FileStream(path, FileMode.Create)) { SerializationEx.Serialize(sm, obj, binary); } }