VbNet · Console
Imports System
Imports System.Collections.Generic
Imports System.Collections
Imports System.IO
Imports System.Text
Imports System.Linq
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.Serialization
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Xml.Linq
Imports System.Xml.XPath
Imports System.Xml.Schema
' https://stackoverflow.com/questions/74229687/how-to-use-datacontractserializer-to-deserialize-an-object-serialized-by-xmlseri
Public Class SMTPSettings
Public Property Host As String
Public Property Port As Integer
Public Property UserName As String
Public Property Password As String
Public Property UseSSL As String
Public Property TestEmailAddress As String
End Class
Public Module Module1
Public Sub Main()
Dim xmlString as String = GetXml()
Dim xml = XElement.Parse(xmlString)
Dim smtp = New SMTPSettings With { _
.Host = xml.Element("Host"),
.Port = xml.Element("Port"),
.UserName = xml.Element("UserName"),
.Password = xml.Element("Password"),
.UseSSL = xml.Element("UseSSL"),
.TestEmailAddress = xml.Element("TestEmailAddress")
}
smtp.Dump()
End Sub
Function GetXml() As String
Dim xml as String = <SMTPSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Host>mail.clubcompete.com</Host>
<Port>26</Port>
<UserName>[email protected]</UserName>
<Password>xxxxxxxxx</Password>
<UseSSL>false</UseSSL>
<TestEmailAddress>[email protected]</TestEmailAddress>
</SMTPSettings>.ToString()
Return xml
End Function
End Module