Сериализация проблемы - PullRequest
       11

Сериализация проблемы

2 голосов
/ 02 ноября 2009

Я получаю следующее исключение: Произошла ошибка при отображении типа 'ValoradorHC.estruturas.dispoHotel'. при попытке сериализации моего класса

Мой код:

 Public Function getXMLdeObjecto(ByVal obj As Object)
        Dim ser As New XmlSerializer(obj.GetType())
        Dim sb As New System.Text.StringBuilder()
        Dim writer As New System.IO.StringWriter(sb)
        ser.Serialize(writer, obj)
        Return sb.ToString()
    End Function

Класс, который я пытаюсь сериализовать:

Public Class estruturas

        <Serializable()> _

        Public Class PedidoDispo

            Private myLocalidade As String
            Public mydataInicio As Date
            Public mydataFim As Date
            Public mynumQuartos As Integer
            Public mynumPessoas As Integer
            Public myordenar As String
            Public myidioma As String

            Public Property Localidade() As String
                Get
                    Return myLocalidade
                End Get
                Set(ByVal Value As String)
                    myLocalidade = Value.Replace(" ", "_")
                End Set
            End Property

            Public Property dataInicio() As String
                Get
                    Return mydataInicio
                End Get
                Set(ByVal Value As String)
                    mydataInicio = Value.Replace(" ", "_")
                End Set
            End Property

            Public Property dataFim() As String
                Get
                    Return mydataFim
                End Get
                Set(ByVal Value As String)
                    mydataFim = Value.Replace(" ", "_")
                End Set
            End Property

            Public Property numQuartos() As String
                Get
                    Return mynumQuartos
                End Get
                Set(ByVal Value As String)
                    mynumQuartos = Value.Replace(" ", "_")
                End Set
            End Property

            Public Property numPessoas() As String
                Get
                    Return mynumPessoas
                End Get
                Set(ByVal Value As String)
                    mynumPessoas = Value.Replace(" ", "_")
                End Set
            End Property

            Public Property ordenar() As String
                Get
                    Return myordenar
                End Get
                Set(ByVal Value As String)
                    myordenar = Value.Replace(" ", "_")
                End Set
            End Property

            Public Property idioma() As String
                Get
                    Return myidioma
                End Get
                Set(ByVal Value As String)
                    myidioma = Value.Replace(" ", "_")
                End Set
            End Property



            Sub New(ByVal localidade As String, ByVal dataInicio As String, ByVal dataFim As String, ByVal numQuartos As Integer, ByVal numPessoas As Integer)
                Me.Localidade = localidade
                Me.dataInicio = DateTime.Parse(dataInicio)
                Me.dataFim = DateTime.Parse(dataFim)
                Me.numQuartos = numQuartos
                Me.numPessoas = numPessoas
                ordenar = "Popularity-desc"
                idioma = "PT"
            End Sub

        End Class


        <Serializable()> _
         Public Class dispoHotel

            Private myPedido As PedidoDispo
            Private mylocalidade As String
            Private mylistaHotel As List(Of hotel)

            Public ReadOnly Property qtdHotels() As String
                Get
                    Return mylistaHotel.Count
                End Get
            End Property

            Public Property listaHotel() As List(Of hotel)
                Get
                    Return mylistaHotel
                End Get
                Set(ByVal Value As List(Of hotel))
                    mylistaHotel = Value
                End Set
            End Property

            Public Property pedido() As PedidoDispo
                Get
                    Return myPedido
                End Get
                Set(ByVal Value As PedidoDispo)
                    myPedido = Value
                End Set
            End Property

            Sub New(ByVal pedido As PedidoDispo)
                Me.pedido = pedido
                listaHotel = New List(Of hotel)
            End Sub

            Sub New()
                listaHotel = New List(Of hotel)
            End Sub

        End Class


        Public Structure hotel

            Dim id As String
            Dim nome As String
            Dim categoria As Integer
            Dim morada As String
            Dim caracteristicas As List(Of String)
            Dim distancia As String
            Dim foto As String
            Dim melhorPreco As String
            Dim precos As Hashtable


        End Structure

    End Class

Ответы [ 2 ]

2 голосов
/ 02 ноября 2009

Ваш класс dispoHotel имеет свойство только для чтения qtdHotels. попытаться заставить сериализатор пропустить его с атрибутом XMLIgnore

1 голос
/ 02 ноября 2009

Вы пытались сделать объект Hotel сериализуемым?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...