XmlSerializer.CanDeserialize(XmlReader) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a value that indicates whether this XmlSerializer can deserialize a specified XML document.
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
Parameters
Returns
true
if this XmlSerializer can deserialize the object that the XmlReader points to; otherwise, false
.
Examples
The following example calls the CanDeserialize method to check whether an XML document can be deserialized.
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
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET