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;
using xmls = System.Xml.Serialization;
[XmlRoot(ElementName = "TextureParameter")]
public class TextureParameter
[XmlAttribute(AttributeName = "pname")]
public string Pname { get; set; }
[XmlAttribute(AttributeName = "value")]
public string Value { get; set; }
public class TextureParameterList : List<TextureParameter>
public static void Test()
var list = new List<TextureParameter>
new TextureParameter { Pname = "TextureMinFilter", Value = "9729" },
new TextureParameter { Pname = "TextureMagFilter", Value = "9728" },
var serializer = MakeListSerializer<TextureParameter>("texparams", "texparam");
var xml = list.GetXml(serializer, true);
Console.WriteLine("Result of serializing {0} with the custom {1}:", list, serializer);
static XmlSerializer MakeListSerializer<T>(string rootName, string elementName)
xmls.XmlAttributeOverrides attributeOverrides = new xmls.XmlAttributeOverrides();
attributeOverrides.Add(typeof(List<T>), new xmls.XmlAttributes()
XmlRoot = new xmls.XmlRootAttribute(rootName),
attributeOverrides.Add(typeof(T), new xmls.XmlAttributes()
XmlType = new xmls.XmlTypeAttribute(elementName),
return new XmlSerializer(typeof(List<T>), attributeOverrides);
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));
T returnValue = default(T);
using (StringReader reader = new StringReader(xmlString))
object result = 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("Environment version: " + Environment.Version);