using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
[XmlRoot("FIBEX", Namespace = fxNameSpace)]
public partial class Fibextoobject
[XmlElement("PROJECT", Namespace = fxNameSpace)]
public Project project { get; set; }
[XmlElement("ELEMENTS", Namespace = fxNameSpace)]
public Elements elements { get; set; }
[XmlAttribute("OID", Namespace = hoNameSpace)]
public string OID { get; set; }
public string ID { get; set; }
[XmlElement("SHORT-NAME", Namespace = hoNameSpace)]
public string shortname { get; set; }
[XmlElement("LONG-NAME", Namespace = hoNameSpace)]
public string longname { get; set; }
[XmlArray("CLUSTERS", Namespace = fxNameSpace)]
[XmlArrayItem("CLUSTER", Namespace = fxNameSpace)]
public List<Cluster> cluster { get; set; }
[XmlType("CLUSTER-TYPE", Namespace = ethernetNameSpace)]
public class ClusterType : Cluster
[XmlType("CLUSTER", Namespace = "")]
[XmlInclude(typeof(ClusterType))]
public string ID { get; set; }
[XmlElement("SHORT-NAME", Namespace = hoNameSpace)]
public string shortname { get; set; }
[XmlElement("SPEED", Namespace = fxNameSpace)]
public string speed { get; set; }
public partial class Fibextoobject
public const string fxNameSpace = "http://www.asam.net/xml/fbx";
public const string hoNameSpace = "http://www.asam.net/xml";
public const string ethernetNameSpace = "http://www.asam.net/xml/fbx/ethernet";
public const string itNameSpace = "http://www.asam.net/xml/fbx/it";
public const string serviceNameSpace = "http://www.asam.net/xml/fbx/services";
public static void Test()
static void TestSerialize()
var root = new Fibextoobject
elements = new Fibextoobject.Elements
cluster = new List<Fibextoobject.Cluster>()
new Fibextoobject.ClusterType
ID = "ID_CLUSTER_MAIN_1",
shortname = "SomeIpDatabase",
Console.WriteLine("\nTest serialization of a fresh intance of {0}:", root);
var root2 = xml.LoadFromXml<Fibextoobject>();
var xml2 = root2.GetXml();
Assert.IsTrue(root.elements.cluster.Select(c => c.GetType()).SequenceEqual(root2.elements.cluster.Select(c => c.GetType())));
Assert.IsTrue(XNode.DeepEquals(XElement.Parse(xml), XElement.Parse(xml2)));
static void TestDeserialize()
var root = xml.LoadFromXml<Fibextoobject>();
var xml2 = root.GetXml();
Console.WriteLine("\nInput XML file:");
Console.WriteLine(XElement.Parse(xml));
Console.WriteLine("\nDeserialized and re-serialized {0}", root);
var xml = @"<fx:FIBEX xmlns:fx=""http://www.asam.net/xml/fbx"" xmlns:ho=""http://www.asam.net/xml"" xmlns:ethernet=""http://www.asam.net/xml/fbx/ethernet"" xmlns:it=""http://www.asam.net/xml/fbx/it"" xmlns:service=""http://www.asam.net/xml/fbx/services"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation="""" VERSION=""4.1.0"">
<fx:CLUSTER xsi:type=""ethernet:CLUSTER-TYPE"" ID=""ID_CLUSTER_MAIN_1"">
<ho:SHORT-NAME>SomeIpDatabase</ho:SHORT-NAME>
<fx:SPEED>1000000000</fx:SPEED>
<fx:IS-HIGH-LOW-BIT-ORDER>false</fx:IS-HIGH-LOW-BIT-ORDER>
<fx:BIT-COUNTING-POLICY>SAWTOOTH</fx:BIT-COUNTING-POLICY>
<fx:PROTOCOL>ETHERNET</fx:PROTOCOL>
<fx:PHYSICAL>OABR</fx:PHYSICAL>
<fx:CHANNEL-REF ID-REF=""ID_CHANNEL_SOME_IP_1""/>
<fx:MAX-FRAME-LENGTH>1500</fx:MAX-FRAME-LENGTH>
<ethernet:MAC-MULTICAST-GROUPS>
<ethernet:MAC-MULTICAST-GROUP ID=""ID_CLUSTER_MAIN_1_ID_MACMULTICASTGROUP_SD_1"">
<ho:SHORT-NAME>SD</ho:SHORT-NAME>
<ethernet:MAC-MULTICAST-ADDRESS>01:00:5E:40:FF:FB</ethernet:MAC-MULTICAST-ADDRESS>
</ethernet:MAC-MULTICAST-GROUP>
<ethernet:MAC-MULTICAST-GROUP ID=""ID_CLUSTER_MAIN_1_ID_MACMULTICASTGROUP_BROADCAST_1"">
<ho:SHORT-NAME>BROADCAST</ho:SHORT-NAME>
<ethernet:MAC-MULTICAST-ADDRESS>FF:FF:FF:FF:FF:FF</ethernet:MAC-MULTICAST-ADDRESS>
</ethernet:MAC-MULTICAST-GROUP>
</ethernet:MAC-MULTICAST-GROUPS>
<!--Additional CLUSTER elements omitted-->
<!--PROJECT elements omitted-->
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 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 void Main()
Console.WriteLine("Roslyn 2.0 Compiler; Environment version: " + Environment.Version);
Console.WriteLine("Uncaught exception: ");