■ BinaryFormatter 클래스의 Deserialize 메소드를 사용해 객체를 역직렬화하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; #region 객체 역직렬화하기 - DeserializeObject(objectByteArray) /// <summary> /// 객체 역직렬화하기 /// </summary> /// <param name="objectByteArray">객체 바이트 배열</param> /// <returns>역직렬화 객체</returns> public object DeserializeObject(byte[] objectByteArray) { MemoryStream memoryStream = new MemoryStream(objectByteArray); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Context = new StreamingContext(StreamingContextStates.Clone); return binaryFormatter.Deserialize(memoryStream); } #endregion |