Circular references

Humans tend to choose a partner for (a part of their) life:


    public class Human
    {
        public string Name { get; set; }
        public Human Partner { get; set; }
    }

    Human alice = new Human() { Name = "Alice" };
    Human bob = new Human() { Name = "Bob" };
    alice.Partner = bob;
    bob.Partner = alice;

    using (Stream stream = File.Open("partners.xml", FileMode.Create, FileAccess.Write))
    {
        Blueprint.Serialize(stream, alice);
    }        
        

Blueprints detects the circular reference and creates a link when it first encounters an object that would otherwise be serialized for the second time:


    <Blueprint xmlns:blueprints="http://const.nl/blueprints" id="54bd65c2-b378-4238-97ba-1d9225adbf8d" blueprints:type="MyApplication.Human, MyApplication">
      <Name>Alice</Name>
      <Partner>
        <Name>Bob</Name>
        <Partner blueprints:link="#54bd65c2-b378-4238-97ba-1d9225adbf8d" />
      </Partner>
    </Blueprint>