2013-05-26 20 views
9

aşağıda sınıfı aşağıdaki hatayı alıyorum kodlamak için kullanılamaz. Karmaşık türleri kodlamak için XmlAttribute/XmlText kullanılamaz.XmlAttribute/xmlText karmaşık türleri

Neden olduğu hakkında herhangi bir düşünce?

[DataContract] 
[Serializable] 
[XmlRoot("ingredient")] 
public class Ingredient 
{ 
    private string id; 
    private string name; 
    private string description; 

    private IngredientNutrient[] nutrients; 

    public Ingredient(string id, string name, string description, IngredientNutrient[] nutrients) 
    { 
     this.id = id; 
     this.name = name; 
     this.description = description; 
     this.nutrients = nutrients; 
    } 

    public Ingredient(string id, string name, string description) 
    { 
     this.id = id; 
     this.name = name; 
     this.description = description; 
    } 

    public Ingredient() 
    { 

    } 

    [DataMember] 
    [XmlAttribute("id")] 
    public string ID 
    { 
     get { return this.id; } 
     set { this.id = value; } 
    } 

    [DataMember] 
    [XmlAttribute("name")] 
    public string Name 
    { 
     get { return this.name; } 
     set { this.name = value; } 
    } 

    [DataMember] 
    [XmlAttribute("description")] 
    public string Description 
    { 
     get { return this.description; } 
     set { this.description = value; } 
    } 

    [DataMember] 
    [XmlArray("nutrients")] 
    [XmlArrayItem("ingredientnutrient")] 
    public IngredientNutrient[] Nutrients 
    { 
     get { return this.nutrients; } 
     set { this.nutrients = value; } 
    } 

} 

cevap

27

Muhtemelen [XmlElement] yerine [XmlAttribute] kullanmak zorunda kalacaktır. Bir özellik karmaşık bir tür olamaz.

1

Başka bir öneri: root öğesinin altındaki (liste) özellikler için öneki dışarıda bırakın.