using System.Collections.Generic;
using System.Xml.Serialization;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Globalization;
using System.ComponentModel.DataAnnotations;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
public partial class PartList
public List<string> Name { get; } = new List<string>();
public List<string> Data { get; } = new List<string>();
public List<string> OtherData { get; } = new List<string>();
[System.Xml.Serialization.XmlElementAttribute("Name", typeof(Name), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlElementAttribute("Data", typeof(Data), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlElementAttribute("OtherData", typeof(OtherData), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ValueWrapper<string>[] Values
var list = new List<ValueWrapper<string>>();
for (int i = 0, count = Math.Max(Name.Count, Math.Max(Data.Count, OtherData.Count)); i < count; i++)
list.Add(new Name { Value = Name[i] });
list.Add(new Data { Value = Data[i] });
list.Add(new OtherData { Value = OtherData[i] });
Name.AddRange(value.OfType<Name>().Select(v => v.Value));
Data.AddRange(value.OfType<Data>().Select(v => v.Value));
OtherData.AddRange(value.OfType<OtherData>().Select(v => v.Value));
public class Name : ValueWrapper<string> { }
public class Data : ValueWrapper<string> { }
public class OtherData : ValueWrapper<string> { }
public abstract class ValueWrapper<T> : ValueWrapper where T : IConvertible
public override object GetValue() => Value;
public T Value { get; set; }
public abstract class ValueWrapper
public abstract object GetValue();
[XmlRoot("Part", Namespace = "")]
public PartList List { get; set; }
public static void Test()
Name = { "Some Test", "Other Lama" },
Data = { "123131313", "331331313" },
OtherData = { "0.11", "0.02" },
var xml = part.GetXml(true);
Console.WriteLine("\nInitially serialized {0}", part);
var part2 = xml.LoadFromXml<Part>();
var xml2 = part.GetXml(true);
Console.WriteLine("\nDeserialized and re-serialized {0}", part);
Assert.IsTrue(XNode.DeepEquals(XElement.Parse(xml), XElement.Parse(xml2)));
Assert.IsTrue(XNode.DeepEquals(XElement.Parse(xml), XElement.Parse(GetDesiredXml())));
Console.WriteLine("\nActual and expected XML are equivalent.");
static string GetDesiredXml()
<OtherData>0.11</OtherData>
<OtherData>0.02</OtherData>
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");
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, bool omitStandardNamespaces)
return obj.GetXml(null, omitStandardNamespaces);
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 void Main()
Console.WriteLine("Roslyn 2.0 Compiler; Environment version: " + Environment.Version);
Console.WriteLine("Uncaught exception: ");