ObjectGraph Sample

Back to summary

Source

using System.Collections.Generic;

namespace XmlSerializersTest.Samples
{
    [Title("Object graph")]
    public class ObjectGraph
    {
        public string Value { get; set; }
        public List<ObjectGraph> Links { get; set; }

        public static ObjectGraph GetSampleGraph()
        {
            var world = new ObjectGraph { Value = "World" };
            var europe = new ObjectGraph { Value = "Europe" };
            var asia = new ObjectGraph { Value = "Asia" };
            var turkey = new ObjectGraph { Value = "Turkey" };

            world.Links = new List<ObjectGraph> { europe, asia };
            europe.Links = new List<ObjectGraph> { turkey };
            asia.Links = new List<ObjectGraph> { turkey };
            return world;
        }
    }
}

WCF-ref Serializer

<ObjectGraph xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/XmlSerializersTest.Samples">
  <Links z:Id="2" z:Size="2">
    <ObjectGraph z:Id="3">
      <Links z:Id="4" z:Size="1">
        <ObjectGraph z:Id="5">
          <Links i:nil="true" />
          <Value z:Id="6">Turkey</Value>
        </ObjectGraph>
      </Links>
      <Value z:Id="7">Europe</Value>
    </ObjectGraph>
    <ObjectGraph z:Id="8">
      <Links z:Id="9" z:Size="1">
        <ObjectGraph z:Ref="5" i:nil="true" />
      </Links>
      <Value z:Id="10">Asia</Value>
    </ObjectGraph>
  </Links>
  <Value z:Id="11">World</Value>
</ObjectGraph>