-1
我試圖序列化和反序列化vb.net中的一些數據。以下是我如何序列化數據;vb.net中的動態類型名稱
調用例程;
SaveData("Reports", GetType(List(Of reports)), allreports)
該子本身;
Private Sub SaveData(ByVal loc As String, ByVal ttyyee As System.Type, ByVal data As Object)
Dim writer As New System.Xml.Serialization.XmlSerializer(ttyyee)
Dim file As New System.IO.StreamWriter(
"c:\Data\" & loc & ".xml")
writer.Serialize(file, data)
file.Close()
End Sub
這似乎工作正常。但是,當我嘗試向後做同樣的事情時,我得到一個錯誤。這是代碼;
調用;
LoadData("Reports", GetType(List(Of reports)), allreports)
The Sub;
Private Sub LoadData(ByVal loc As String, ByVal ttyyee As System.Type, ByVal data As Object)
Dim reader As New System.Xml.Serialization.XmlSerializer(ttyyee)
Dim file As New System.IO.StreamReader(
"c:\Data\" & loc & ".xml")
data = CType(reader.Deserialize(file), ttyyee)
End Sub
的問題是則傳遞給函數的參數ttyyee
。我得到的錯誤:
type ttyyee is not defined.
我打算用這個序列化和反序列化的一堆不同類型的,所以我不希望明確聲明它,而傳遞的類型如保存子。有任何想法嗎?所有的
也許'list of'與它有關係。你有沒有嘗試創建另一個類,基本上是一個'報告列表'並通過 – Claudius
@Claudius錯誤發生在我運行代碼之前(它不會像這樣編譯)。 – FraserOfSmeg
隨機downvote沒有評論.... – FraserOfSmeg