Serialize read-only collection without implementing IXmlSerializable

918 Views Asked by At

I have a class :

[Serializable]
public class Profile
{
    [XmlAttribute]
    private string[] permissions;
    public string[] Permissions
    {
        get { return permissions; }
        set { permissions = value; }
    }
}

I want to serialize it in XML with XmlSerializer and I also have to be compliant with FxCop. The problem is that FxCop only wants to expose read-only collection for properties, but of course a ReadOnlyCollection is not serializable. I do not want to implement IXmlSerializable because it's too painful. Is there any other solution ?

1

There are 1 best solutions below

0
On

Options:

  • you could use a List-of-String rather than a string-array; this doesn't need a setter, as the collection can be manipulated directly
  • you could accept that fxcop is always going to be a generalisation, and that sometimes the generalisation is not appropriate to your specific context - meaning: simply ignore fxcop in this case