Xml Serialization of ReadOnlyCollections
<p>I have some container classes that expose their collections through a ReadOnlyCollection. Custom Methods are provided to Add and Remove from the collection which also perform some custom logic.</p>

<p>For example:</p>

<pre><code>public class Foo
{
    List&lt;Bar&gt; _barList = new List&lt;Bar&gt;();

    public ReadOnlyCollection&lt;Bar&gt; BarList
    {
        get { return _barList.AsReadOnly(); }
    }

    public void AddBar(Bar bar)
    {
        if (bar.Value &gt; 10)
            _barList.Add(bar);
        else
            MessageBox.Show("Cannot add to Foo. The value of Bar is too high");
    }
    public void RemoveBar(Bar bar)
    {
        _barList.Remove(bar);
        // Foo.DoSomeOtherStuff();
    }

}

public class Bar
{
    public string Name { get; set; }
    public int Value { get; set; }
}
</code></pre>

<p>This is all well and good but when i come to serialise Foo with the Xml Serializer an exception is thrown.</p>

<p>Can anyone offer a good way of going about this?</p>

<p>Thanks</p>
