这是我的两个类:类 Characteristic 和 Definition :
[DataContract]
public class Characteristic
{
[DataMember]
public Definition Definition { get; set; }
}
[Serializable]
public class Definition
{
[XmlAttribute]
public int id;
[XmlAttribute]
public stringName;
}
这是我的实现:
Characteristic lstChars = new Characteristic()
{
Definition = new Definition()
{
id = Dimension.ID,
name = Dimension.Name
}
};
我得到这个结果:
<Characteristic>
<Definition>
<id>6</id>
<name>ACTIVITY</name>
</Definition>
我的目标是得到这个结果:
<Characteristic>
<Definition id="6" Name= "ACTIVITY" />