如何使用关键字名称反序列化属性?

时间:2014-08-04 18:37:03

标签: c# xml serialization keyword

我有以下XML代码:

<sees direction="NE"/>
<sees direction="E"/>
<sees direction="SE">
    <object>diamond</object>
    <background>green</background>
</sees>
<sees direction="SW">
    <background>green</background>
</sees>

我对对象标签的反序列化有问题。首先我写了manualy属性,然后我使用XSD工具生成类,并编辑了XMLElementAttribute。

System.Xml.Serialization.XmlElementAttribute("object", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string @object
{
    get
    {
        return this.objectField;
    }
    set
    {
        this.objectField = value;
    }
}

即使在编译时我也没有找到满足此字段的方法,所有其他字段(例如背景)都能正常工作。

有什么东西我错过了吗?

1 个答案:

答案 0 :(得分:1)

你应该可以这样做:

[XmlElement("object")]
public string WhatEverNameYouLike {get; set;}
相关问题