How to serialize List using XML serialization

Okay so this one is filed under the “I keep looking up the same things” category. In .Net 1 lists of objects were commonly serialized either using an Array or an ArrayList property:

/// <summary>
/// List Item permissions to be given to this group
/// </summary>
[XmlArray("ListItems"), XmlArrayItem("ListItemPermissions", typeof(ListItemPermissions))]
public ArrayList ListItems
        get { return _listItems; }
        set { _listItems = value; }
public Group[] Groups
        get { return this.groups; }
        set { this.groups = value; }

In .net 2.0 List<T> can be serialized by adding the XmlArray attribute in the property declaration, as follows:

public List<PortalAudience> Audiences { get; set; }


Tagged , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: