XmlSerializer.CanDeserialize(XmlReader) 메서드


XmlSerializer가 지정된 XML 문서를 역직렬화할 수 있는지 여부를 나타내는 값을 가져옵니다.Gets a value that indicates whether this XmlSerializer can deserialize a specified XML document.

 virtual bool CanDeserialize(System::Xml::XmlReader ^ xmlReader);
public virtual bool CanDeserialize (System.Xml.XmlReader xmlReader);
abstract member CanDeserialize : System.Xml.XmlReader -> bool
override this.CanDeserialize : System.Xml.XmlReader -> bool
Public Overridable Function CanDeserialize (xmlReader As XmlReader) As Boolean

매개 변수


역직렬화할 문서를 가리키는 XmlReader입니다.An XmlReader that points to the document to deserialize.



XmlSerializer가 가리키는 개체를 이 XmlReader가 역직렬화할 수 있으면 true이고, 그렇지 않으면 false입니다.true if this XmlSerializer can deserialize the object that the XmlReader points to; otherwise, false.


다음 예제에서는 메서드를 호출 CanDeserialize 하 여 XML 문서를 deserialize 할 수 있는지 여부를 확인 합니다.The following example calls the CanDeserialize method to check whether an XML document can be deserialized.

   void TestDocument( String^ filename, Type^ objType )
      // Using a FileStream, create an XmlTextReader.
      Stream^ fs = gcnew FileStream( filename,FileMode::Open );
      XmlReader^ reader = gcnew XmlTextReader( fs );
      XmlSerializer^ serializer = gcnew XmlSerializer( objType );
      if ( serializer->CanDeserialize( reader ) )
         Object^ o = serializer->Deserialize( reader );
private void TestDocument(string filename, Type objType)
   // Using a FileStream, create an XmlTextReader.
   Stream fs = new FileStream(filename, FileMode.Open);
   XmlReader reader = new XmlTextReader(fs);
   XmlSerializer serializer = new XmlSerializer(objType);
         Object o = serializer.Deserialize(reader);

Private Sub TestDocument _
                (ByVal filename As String, _
                 ByVal objType As Type)
    ' Using a FileStream, create an XmlTextReader.
    Dim fs As New FileStream(filename, FileMode.Open)
    Dim reader As New XmlTextReader(fs)
    Dim serializer As New XmlSerializer(objType)
    If serializer.CanDeserialize(reader) Then
        Dim o As Object = serializer.Deserialize(reader)
    End If
End Sub

적용 대상

추가 정보