2

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 ?

Peekyou
  • 471
  • 1
  • 5
  • 21
  • Which serializer are you using? I ask because XmlAttribute doesn't work on collections, or on private fields - and Serializable isn't used by XmlSerializer – Marc Gravell Jul 24 '13 at 10:02
  • K; currently neither of those attributes does anything useful - you might want to remove both [Serializable] and [XmlAttribute] to avoid confusion – Marc Gravell Jul 24 '13 at 10:07

1 Answers1

0

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
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900