我正在尝试构建一个可以映射到此 XML 结构的类,但不知道如何构建。我在这里看到了一些例子,如果元素值是一个字符串,我可以使用 [XmlText]。在我的例子中,元素值是 bool 值。我应该如何构建我的“服务”类?
(我认为)我知道如何处理“服务”元素 :-)。它只是一组“服务”对象。我只是不确定如何构建“服务”类。
<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyConfigs>
<Services>
<Service Name="ServiceName">true</Service>
</Services>
</MyConfigs>
我有这个:
[XmlArray("Services")]
[XmlArrayItem("Service")]
public Service[] Services { get; set; }
还有这个:
public class Service
{
[XmlAttribute]
public string Name { get; set; }
// How do I get the boolean value here?????
}
最佳答案
尝试
[XmlText]
public bool ServiceValue {get;set;}
关于c# - 反序列化具有字符串属性的 bool 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11798281/