-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