【发布时间】:2017-04-25 07:41:26
【问题描述】:
我有以下示例结构的类:
public class DataClass{
public String Field1{ get; set; }
public Int32 Field2{ get; set; }
public Int32 Field3{ get; set; }
}
我必须为每个字段添加一个固定属性,以便输出看起来像:
<DataClass>
<Field1 code="code#1">Value of Field1</Field1>
<Field2 code="code#2">Value of Field2</Field2>
<Field3 code="code#3">Value of Field3</Field3>
</DataClass>
如果不为每个字段编写包装类,这是否可能? 比如:
public class DataClass{
[XmlElement(FixedAttribute="code#1")]
public String Field1{ get; set; }
[XmlElement(FixedAttribute="code#2")]
public Int32 Field2{ get; set; }
[XmlElement(FixedAttribute="code#3")]
public Int32 Field3{ get; set; }
}
亲切的问候
【问题讨论】:
标签: c# xml xmlserializer