开发者

Silverlight Saving a Class Instance to Isolated Storage

开发者 https://www.devze.com 2023-03-22 08:40 出处:网络
Im just wondering how I go about saving an instance of a class to the silverlight isolated storage. I also need to know if it possible that the class that we save to isolated storage can have a list o

Im just wondering how I go about saving an instance of a class to the silverlight isolated storage. I also need to know if it possible that the class that we save to isolated storage can have a list of instances of another class. Here is an example of the situation:

Public Class MySettingsToStore

    private mPropertyA as string
    Public Property PropertyA() As string
    Get
        Return mPropertyA 
    End Get
    Set(ByVal value As string)
        mPropertyA = value
    End Set
    End Property

    private mlstOfSubClass as List(Of MySubClass)
    Public Property lstOfSubClass() As List(Of MySubClass)
    Get
        Return mlstOfSubClass 
    End Get
    Set(ByVal value As List(Of MySubClass))
        mlstOfSubClass = value
    End Set
    End Property
End Class

Public Class MySubClass
    private mPropertyA as string
    Public Property PropertyA() As string
    G开发者_如何学JAVAet
        Return mPropertyA 
    End Get
    Set(ByVal value As string)
        mPropertyA = value
    End Set
    End Property

   private mPropertyB as string
    Public Property PropertyB() As string
    Get
        Return mPropertyB 
    End Get
    Set(ByVal value As string)
        mPropertyB = value
    End Set
    End Property


End Class

So basically on load of the application I want to check if there is an instance of MySettingsToStore in the isolatedStorage if not I will create one and save it (and update it when needed), so the next time the application is started there will be an instance in the isolatedstorage to load.

Does anyone know how I go about this? Hope someone can help. Thanks in advance


One word: XMLSerializer

To elaborate a bit, you can serialize any class with public properties to a stream (e.g. in Isolated storage) and reverse that process on startup to load an existing file in ISO storage.

If a property is a collection of other classes, they too will be stored and restored by using XMLSerializer.

0

精彩评论

暂无评论...
验证码 换一张
取 消