/// <summary> /// Read this IBinarySerializable item in from the binary data at the given file path. /// Throws exceptions encountered during reading (common if reading a file with the wrong class). /// </summary> /// <param name="item">IBinarySerializable item to read</param> /// <param name="filePath">File Path to read binary form of item from</param> public static void FileRead(this IBinarySerializable item, string filePath) { using (FileStream s = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { BinaryReader reader = new BinaryReader(s); item.ReadBinary(reader); } }
public static void Read(this IBinarySerializable item, string filePath) { string fullPath = FullPath(filePath); using (SerializationContext context = new SerializationContext(new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))) { item.ReadBinary(context); } }