我只是想知道如何将类的实例保存到silverlight隔离存储中。我还需要知道我们保存到隔离存储的类是否可能具有另一个类的实例列表。以下是一个例子:
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
Get
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
所以基本上在应用程序的加载我要检查在IsolatedStorage中是否有MySettingsToStore的实例,如果不是我将创建一个并保存它(并在需要时更新它),所以下次应用程序在那里启动时将成为Isolatedstorage中要加载的实例。
有谁知道我怎么回事?希望有人能提供帮助。提前致谢
答案 0 :(得分:2)
一个字:XMLSerializer
为了详细说明,您可以将具有公共属性的任何类序列化为流(例如,在隔离存储中),并在启动时反转该过程以在ISO存储中加载现有文件。
如果某个属性是其他类的集合,那么它们也将使用XMLSerializer进行存储和恢复。