Imports System.Xml.Serialization
Imports System.Collections.Generic
<XmlInclude(GetType(LoopTerminatedType))> _
<XmlInclude(GetType(LoopDynamicLengthType))> _
Public MustInherit Class PosResponseLoop
<XmlType("loopTerminatedType")> _
Public Class LoopTerminatedType
<XmlType("loopDynamicLengthType")> _
Public Class LoopDynamicLengthType
<XmlElement("loop")> Public prLoop() As PosResponseLoop
Dim root as New RootObject With _
.prLoop = new PosResponseLoop() { new LoopTerminatedType(), new LoopDynamicLengthType() }
Public Module XmlSerializationHelper
<System.Runtime.CompilerServices.Extension> _
Public Function LoadFromXML(Of T)(xmlString As String) As T
Using reader As New StringReader(xmlString)
Return DirectCast(New XmlSerializer(GetType(T)).Deserialize(reader), T)
<System.Runtime.CompilerServices.Extension> _
Public Function GetXml(Of T)(obj As T, Optional omitStandardNamespaces As Boolean = False) As String
Dim ns As XmlSerializerNamespaces = Nothing
If omitStandardNamespaces Then
ns = New XmlSerializerNamespaces()
Using textWriter = New StringWriter()
Dim settings = New XmlWriterSettings() With { _
Using xmlWriter = System.Xml.XmlWriter.Create(textWriter, settings)
Dim serializer as New XmlSerializer(obj.GetType())
serializer.Serialize(xmlWriter, obj, ns)
Return textWriter.ToString()