首页 新闻 搜索 专区 学院

反序列化问题

0
[已解决问题] 解决于 2009-10-27 15:43

做了个可序列化的类,当xml反序列化的时候,如果哪个节点缺少了,那也不会报错,而是默认的将缺少的节点设为默认值。如何写才能在缺少节点的时候报错?

 

Public Shared Function Deserialize(ByVal xml As String, ByRef obj As DisbursementList, ByRef exception As System.Exception) As Boolean
        exception = Nothing
        obj = Nothing
        Try
            Dim stringReader As System.IO.StringReader = New System.IO.StringReader(xml)
            Dim xmlTextReader As System.Xml.XmlTextReader = New System.Xml.XmlTextReader(stringReader)
            Dim xmlSerializer As System.Xml.Serialization.XmlSerializer = New System.Xml.Serialization.XmlSerializer(GetType(DisbursementList))
            obj = CType(xmlSerializer.Deserialize(xmlTextReader), DisbursementList)
            Return True
        Catch ex As System.Exception
            exception = ex
            Return False
        End Try
    End Function

 

驢騎士的主页 驢騎士 | 初学一级 | 园豆:0
提问于:2009-10-19 19:22
< >
分享
最佳答案
0

把节点定义为必须的,也就是序列化时不能略过.

Launcher | 高人七级 |园豆:45045 | 2009-10-20 08:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册