locked
Serialize RRS feed

  • Question

  • Hi, I'm trying to perfom Serializing/De- function. But I can't get how it's works in Win8.

    I have a class Card needed to be serialized. 

    > Dim A As New XmlSerializer(GetType(Card))

    Then I need to write this data to localstorage file

    MSDN example shows:

    ' Create a FileStream to write with.
    Dim writer As New FileStream(filename, FileMode.Create)
    ' Serialize the object, and close the TextWriter
    serializer.Serialize(writer, i)
    writer.Close()

    But there is no kind of FileStream in Win8. How to create file stream and write serialized data there?..


    Aleksey

    Thursday, December 5, 2013 10:26 PM

Answers

  • Here is how should looks reply

    Dim Cards As New ObservableCollection(Of Card)
    Cards.Add(New Card)
    Cards(0).Name = "Hello!"

    Dim sw = New StringWriter
    Dim serializer = New XmlSerializer(GetType(ObservableCollection(Of Card)))
    serializer.Serialize(sw, Cards)
    Dim B As String = sw.ToString()

    Dim Cards2 As New ObservableCollection(Of Card)
    Dim sr As New StringReader(B)
    Dim deserializer = New XmlSerializer(GetType(ObservableCollection(Of Card)))
    Cards2 = deserializer.Deserialize(sr)


    Aleksey

    • Marked as answer by Newfriend Saturday, December 7, 2013 1:38 AM
    Saturday, December 7, 2013 1:38 AM

All replies