【发布时间】:2014-10-06 13:20:19
【问题描述】:
我的 XmlSerializer 有问题。我尝试反序列化这个文件:
<MyClass Id="12">
<ProblemHere Value="8"/>
<OtherElement>0</OtherElement>
<fdp>NTM</fdp>
</MyClass>
在这个类中:
[XmlType(TypeName = "MyClass")]
public class MyClass
{
[XmlAttribute(AttributeName = "Id")]
public int Id { get; set; }
//Here I try somes head but it's a failure
public int ProblemHere { get; set; }
public int OtherElement{ get; set; }
public string fdp{get; set}
}
您可能理解,我想要将ProblemHere 设置为其值(此处为8)。有什么简单的方法可以做到这一点,还是我必须创建一个带有int Value 属性的ProblemHere 类(对我来说似乎有点矫枉过正)?
【问题讨论】:
-
您的另一个选择是手动进行序列化。
标签: c# .net xml xml-serialization