The type getting deserialized/ serialized is (some parts are excluded):
public class Entry : IEnumerable<Entry>{
public string name { get; set; }
public List<Entry> items { get; set; }
public Entry()
{
}
public IEnumerator<Entry> GetEnumerator()
{
yield return this;
if (items != null && items.Count > 0)
{
foreach (var child in items)
{
foreach (var grandChild in child)
yield return grandChild;
}
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Which represents a tree data hierarchy with no circular references.
While IEnumerable interface is implemented, is implemented to recurse over every sub entry below current, it results on a weird output (see at the end).
If the IEnumerable interface is removed, it gets serialized properly.
Deserialization works normally both ways (from original data).
No errors or warnings.
So my question is, is this a bug or am I doing something terribly wrong. Any insight is appreciated.
Output (partial):
- &o0
- *o0
- &o1
- *o1
- &o2
- *o2
- &o3
- *o3
- &o4
- *o4
- &o5
- *o5
- &o6
- *o6
- &o7
- *o7
- *o4
- *o5
- *o6
- *o7
- *o3
Expected output (partial):
- name: Runtime
items:
- name: Util
items:
- name: NaturalStringComparer
items: