Hi,

You need to look into Using Generics in the .NET Framework. Generics allow you pass different types to a Routine and then deal with them as per the Type that was passed. As a quick Example, I use two regular Extension Methods in my regular coding to Serialize and Deserialize different object types into a JSON Structure. i.e:-

vb.net Code:
  1. <Extension()>
  2. Public Function SerializeToJSON(Of T)(ByVal dataToSerialize As T) As String
  3.   Dim jsonTool As New JavaScriptSerializer
  4.   Return jsonTool.Serialize(dataToSerialize)
  5. End Function
  6.  
  7. <Extension()>
  8. Public Function DeserializeFromJSON(Of T)(ByVal dataToDeserialize As String, ByVal typeToDeserializeTo As T) As T
  9.   Dim jsonTool As New JavaScriptSerializer
  10.   Return jsonTool.Deserialize(Of T)(dataToDeserialize)
  11. End Function

Even though this is Not XML this does demonstrate the principle of Serializing and Deserializing any object type using Generics.

I will now leave this to you to get working with XML rather than JSON.


Hope that helps.

Cheers,

Ian