방법: 개체 Deserialize

개체를 deserialize할 때는 전송 형식에 따라 스트림을 만들지 파일 개체를 만들지 여부가 결정됩니다. 전송 형식이 결정된 뒤에는 필요에 따라 Serialize 또는 Deserialize 메서드를 호출할 수 있습니다.

개체를 deserialize하려면

  1. deserialize할 개체의 형식을 사용하여 XmlSerializer를 생성합니다.

  2. 개체의 복제본을 생성할 Deserialize 메서드를 호출합니다. deserialize할 때는 개체를 파일로 deserialize하는(스트림으로 deserialize할 수도 있음) 다음 예제처럼, 반환된 개체를 원래의 형식으로 캐스팅해야 합니다.

    Dim myObject As MySerializableClass
    ' Construct an instance of the XmlSerializer with the type
    ' of object that is being deserialized.
    Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(MySerializableClass))
    ' To read the file, create a FileStream.
    Dim myFileStream As FileStream = _
    New FileStream("myFileName.xml", FileMode.Open)
    ' Call the Deserialize method and cast to the object type.
    myObject = CType( _
    mySerializer.Deserialize(myFileStream), MySerializableClass)
    
    MySerializableClass myObject;
    // Construct an instance of the XmlSerializer with the type
    // of object that is being deserialized.
    XmlSerializer mySerializer = 
    new XmlSerializer(typeof(MySerializableClass));
    // To read the file, create a FileStream.
    FileStream myFileStream = 
    new FileStream("myFileName.xml", FileMode.Open);
    // Call the Deserialize method and cast to the object type.
    myObject = (MySerializableClass) 
    mySerializer.Deserialize(myFileStream)
    

참고 항목

작업

방법: 개체 Serialize

개념

XML Serialization 소개

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.