using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
public class ConfigProperty
public string NameKey { get; set; }
public List<int> DeviceIdentifierIndices { get; private set; }
DeviceIdentifierIndices = new List<int>();
public class ConfigProperty
public string NameKey { get; set; }
[XmlAttribute("DeviceIdentifierIndices")]
public int[] DeviceIdentifierIndicesArray
get { return DeviceIdentifierIndices.ToArray(); }
DeviceIdentifierIndices.Clear();
DeviceIdentifierIndices.AddRange(value);
public List<int> DeviceIdentifierIndices { get; private set; }
DeviceIdentifierIndices = new List<int>();
public class ConfigProperty
public string NameKey { get; set; }
[XmlAttribute("DeviceIdentifierIndices")]
public string XmlDeviceIdentifierIndices
get { return String.Join(" ", DeviceIdentifierIndices.Select(i => XmlConvert.ToString(i))); }
var newList = (value ?? "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(s => XmlConvert.ToInt32(s)).ToList();
DeviceIdentifierIndices.Clear();
DeviceIdentifierIndices.AddRange(newList);
public List<int> DeviceIdentifierIndices { get; private set; }
DeviceIdentifierIndices = new List<int>();
public static void Test()
var config = new V1.ConfigProperty
NameKey = "lightningInterval",
DeviceIdentifierIndices = { 18, 22 },
var xml = config.GetXml(omitStandardNamespaces : true);
var config2 = xml.LoadFromXml<V2.ConfigProperty>();
Assert.IsTrue(config.DeviceIdentifierIndices.SequenceEqual(config2.DeviceIdentifierIndices));
Assert.AreEqual(config.NameKey, config2.NameKey);
var config3 = xml.LoadFromXml<V3.ConfigProperty>();
Assert.IsTrue(config.DeviceIdentifierIndices.SequenceEqual(config3.DeviceIdentifierIndices));
Assert.AreEqual(config.NameKey, config3.NameKey);
Assert.IsTrue(XNode.DeepEquals(XElement.Parse(xml), XElement.Parse(config2.GetXml(omitStandardNamespaces : true))));
Assert.IsTrue(XNode.DeepEquals(XElement.Parse(xml), XElement.Parse(config3.GetXml(omitStandardNamespaces : true))));
public static class XmlSerializationHelper
public static T LoadFromXml<T>(this string xmlString, XmlSerializer serial = null)
serial = serial ?? new XmlSerializer(typeof(T));
using (var reader = new StringReader(xmlString))
return (T)serial.Deserialize(reader);
public static string GetXml<T>(this T obj, XmlSerializer serializer = null, bool omitStandardNamespaces = false)
XmlSerializerNamespaces ns = null;
if (omitStandardNamespaces)
ns = new XmlSerializerNamespaces();
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings() { Indent = true };
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
(serializer ?? new XmlSerializer(obj.GetType())).Serialize(xmlWriter, obj, ns);
return textWriter.ToString();
public static string GetOuterXml(this XmlNode node, bool indent = true)
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings
OmitXmlDeclaration = true,
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
return textWriter.ToString();
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.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];