XmlSerializer.CanDeserialize(XmlReader) Metoda

Definice

Získá hodnotu, která označuje, zda to XmlSerializer může deserializovat zadaný dokument XML.

public:
 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

Parametry

xmlReader
XmlReader

Dokument XmlReader odkazuje na deserializaci dokumentu.

Návraty

Boolean

true pokud to XmlSerializer může deserializovat objekt, na který XmlReader odkazuje; v opačném případě false.

Příklady

Následující příklad volá metodu CanDeserialize ke kontrole, zda může být dokument XML deserializován.

private:
   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 );
      }
      fs->Close();
   }
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);
   if(serializer.CanDeserialize(reader))
      {
         Object o = serializer.Deserialize(reader);
      }
   fs.Close();
}
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
    fs.Close()
End Sub

Platí pro

Viz také