我有 ac#MVC 模型,我想将其序列化为 XML 文档,如下所示:
<Vehicle>
<Type color="red" speed="50mph">Ford</Type>
<Type color="blue" speed="70mph">Toyota</Type>
</Vehicle>
这是模型:
[Serializable]
public class Production
{
public List<Vehicle> Vehicles { get; set; }
}
[Serializable]
public class Vehicle
{
[XmlAttribute]
public string color { get; set; }
[XmlAttribute]
public string speed { get; set; }
}
由于类 Vehicle 不是属性,我需要向类添加什么以赋予它例如“福特”或“丰田”的值
现在我有:
var myvehicle = new Vehicle {color = "red", speed = "50mph"};