2
請指導我如何獲得一個泛型類型參數的類型,在波紋管的情況:通用反序列化
Public Function DerializeFromFile(Of T)(ByVal fileName As String) As T
Dim serializer As New XmlSerializer(T.GetType()) '--------------- HELP !!!???
Dim fileStream = New FileStream(fileName,
FileMode.Open, FileAccess.Read, FileShare.Read)
Dim loadedObject As T = DirectCast(serializer.Deserialize(fileStream), T)
Return loadedObject
End Function
它是C#中的typeof(T)',在VB中也必須有類似的語法。也許'TypeOf(T)'? –
在VB中不是typeof,可能是GetType ... – serhio
vb.net的類型:http://msdn.microsoft.com/en-us/library/0ec5kw18.aspx – Ric