using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
[DataContract(Name="SMTPSettings", Namespace = "")]
public class SMTPSettings
[DataMember(Name ="Host", Order = 1)]
public string Host { get; set; }
[DataMember(Name = "Port", Order = 2)]
public int Port { get; set; }
[DataMember(Name = "UserName", Order = 3)]
public string UserName { get; set; }
[DataMember(Name = "Password", Order = 4)]
public string Password { get; set; }
[DataMember(Name = "UseSSL", Order = 5)]
public string UseSSL { get; set; }
[DataMember(Name = "TestEmailAddress", Order = 6)]
public string TestEmailAddress { get; set; }
public static partial class DataContractSerializerHelper
public static string ToContractXml<T>(this T obj, DataContractSerializer serializer = null, XmlWriterSettings settings = null)
serializer = serializer ?? new DataContractSerializer(obj == null ? typeof(T) : obj.GetType());
using (var textWriter = new StringWriter())
settings = settings ?? new XmlWriterSettings { Indent = true };
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
serializer.WriteObject(xmlWriter, obj);
return textWriter.ToString();
public static T FromContractXml<T>(string xml, DataContractSerializer serializer = null)
using (var textReader = new StringReader(xml ?? ""))
using (var xmlReader = XmlReader.Create(textReader))
return (T)(serializer ?? new DataContractSerializer(typeof(T))).ReadObject(xmlReader);
public static void Test()
var dataContractObject = DataContractSerializerHelper.FromContractXml<SMTPSettings>(xml);
dataContractObject.Dump();
static string GetXml() => @"<?xml version=""1.0""?>
<SMTPSettings xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<Host>mail.clubcompete.com</Host>
<UserName>outgoing@clubcompete.com</UserName>
<Password>xxxxxxxxx</Password>
<TestEmailAddress>al@xxxxx-micro.com</TestEmailAddress>
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];