Currently I have written a function to deserialize XML as seen below. How do I change it so I don't have to replace the type every time I want to serialize another object type ? The current object type is cToolConfig. How do I make this function generic ?
Public Shared Function DeserializeFromXML(ByRef strFileNameAndPath As String) As XMLhandler.XMLserialization.cToolConfig
Dim deserializer As New System.Xml.Serialization.XmlSerializer(GetType(cToolConfig))
Dim srEncodingReader As IO.StreamReader = New IO.StreamReader(strFileNameAndPath, System.Text.Encoding.UTF8)
Dim ThisFacility As cToolConfig
ThisFacility = DirectCast(deserializer.Deserialize(srEncodingReader), cToolConfig)
srEncodingReader.Close()
srEncodingReader.Dispose()
Return ThisFacility
End Function
Public Shared Function DeserializeFromXML1(ByRef strFileNameAndPath As String) As System.Collections.Generic.List(Of XMLhandler.XMLserialization.cToolConfig)
Dim deserializer As New System.Xml.Serialization.XmlSerializer(GetType(System.Collections.Generic.List(Of cToolConfig)))
Dim srEncodingReader As IO.StreamReader = New IO.StreamReader(strFileNameAndPath, System.Text.Encoding.UTF8)
Dim FacilityList As System.Collections.Generic.List(Of cToolConfig)
FacilityList = DirectCast(deserializer.Deserialize(srEncodingReader), System.Collections.Generic.List(Of cToolConfig))
srEncodingReader.Close()
srEncodingReader.Dispose()
Return FacilityList
End Function