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;
[XmlRoot(ElementName = "book")]
[XmlElement(ElementName = "author")]
public string Author { get; set; }
[XmlElement(ElementName = "title")]
public string Title { get; set; }
[XmlElement(ElementName = "genre")]
public Genre Genre { get; set; }
[XmlElement(ElementName = "price")]
public decimal Price { get; set; }
[XmlElement(ElementName = "publish_date")]
public string PublishDate { get; set; }
[XmlElement(ElementName = "description")]
public string Description { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlRoot(ElementName = "catalog")]
[XmlElement(ElementName = "book")]
public List<Book> Books { get; set; }
public static void Test()
var filePath = "test.xml";
File.WriteAllText(filePath, GetXml());
public static void Test(string filePath)
using (var reader = XmlReader.Create(filePath))
var serializer = new XmlSerializer(typeof(Catalog));
dupa = ((Catalog)serializer.Deserialize(reader)).Books;
Console.WriteLine("\nResult of deserializing and reserializing the List<Book>: ");
Console.WriteLine(dupa.GetXml(false));
var xml = @"<?xml version=""1.0""?>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>
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("Environment version: " + Environment.Version);
Console.WriteLine("Uncaught exception: ");