Tag: xml binding

如何使用注释从类的属性值派生xml元素名称?

我有具有ID和值以及名称的属性。 我可以使用XmlElement / XmlArray C#注释代表所有具有单个类的人吗? 我想从类属性名称派生xml元素名称 ; 我的class级看起来像: public class Property { public string name; //could be enum public int id; public string value; } 例如: new Property(“property1name”,2,”testvalue”); new Property(“property2name”,10,”anothervalue”); 我想要xml看起来像: 2testvalue 10anothervalue 而不是通常的 property1name2testvalue property2name10anothervalue 换句话说,xmlelement的名称来自类Property的属性名称