Die XML-Serialisierung einer Liste mit Parametern

Habe ich eine Liste innerhalb einer anderen Liste (ein Produkt mit Varianten). Ich würde gerne in der übergeordneten Liste zu haben, die Attribute set (nur ein id und ein name).

Gewünschte Ausgabe

<embellishments>
    <type id="1" name="bar bar foo">
        <row>
            <id>1</id>
            <name>foo bar</name>
            <cost>10</cost>
        </row>      
    </type> 
</embellishments>

Aktuellen Code

[XmlRoot( ElementName = "embellishments", IsNullable = false )]
public class EmbellishmentGroup
{
    [XmlArray(ElementName="type")]
    [XmlArrayItem("row", Type=typeof(Product))]
    public List<Product> List { get; set; }

    public EmbellishmentGroup() {
        List = new List<Product>();
        List.Add( new Product() { Id = 1, Name = "foo bar", Cost = 10m } );
    }
}

public class Product
{
    [XmlElement( "id" )]
    public int Id { get; set; }

    [XmlElement( "name" )]
    public string Name { get; set; }

    [XmlElement( "cost" )]
    public decimal Cost { get; set; }
}

Aktuellen Ausgabe

<embellishments>
    <type>
        <row>
            <id>1</id>
            <name>foo bar</name>
            <cost>10</cost>
        </row>
    </type>
</embellishments>

InformationsquelleAutor Kieran | 2012-12-11
Schreibe einen Kommentar