tags:

views:

42

answers:

0

Hi, Given I have the following classes,

public class Foo
{
    public string Name { get; set; }
    public IEnumerable<Bar> Bars { get; set; }
}

public class Bar
{
    public int Amount { get; set; }
    public Foo Foo { get; set; }
}

public class BarItems
{
    public string SomeString { get; set; }
    public IEnumerable<Bar> Bars { get; set; }
}

In my DTO models. While doing some fancy stuff, I want to serialize an "BarItems" to JSON using the JavaScriptSerializer. In the JSON i want to be able to access the "Name" of the "Foo" object.

But as the most of us know I get an RecursionLimit Exceeded. In some other place of the code I want to Serialize an "Foo" object with all its Bars, so adding [ScriptIgnore] on Bars-property won't work.

By my logic; setting an recursiondepth of 3 in the Serializer while serializing an "BarItems" should fix it, but sadly it still throws that exception. Anyone got an idea make the serializer work as I want?

Thanks!