ObjectGraphWithCycle Sample

Back to summary

Source

using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;

namespace XmlSerializersTest.Samples
{
    [Title("Object graph with cycle")]
    [SkipSerializer("Standard", "Object graph with cycle causes unrecoverable stack overflow")]
    [SkipSerializer("XAML", "Object graph with cycle causes unrecoverable stack overflow")]
    public class ObjectGraphWithCycle
    {
        public string Value { get; set; }

        [XmlIgnore]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public List<ObjectGraphWithCycle> Links { get; set; }

        public static ObjectGraphWithCycle GetSampleGraphWithCycle()
        {
            var node = new ObjectGraphWithCycle { Value = "root" };
            node.Links = new List<ObjectGraphWithCycle> {node};
            return node;
        }
    }
}

XAML Serializer

Object graph with cycle causes unrecoverable stack overflow

Deserialization skipped