0

我有一个枚举属性。我希望此属性的序列化 XML 是枚举的拆分后的驼峰式字符串,反之亦然。

我有两个功能,一个是ConcatCamelCase,另一个是SplitCamelCase,我希望序列化程序相应地使用它们,这是否可以通过仅用属性装饰字段来实现?

如果不是,那么其他选项是什么而不必弄乱所有其他领域?

4

2 回答 2

1

你必须做这样的事情:

public class SomeClass {
    [XmlIgnore]
    public MyEnum MyRealProperty {get;set;}

    [XmlElement("MyRealProperty")]
    [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
    public string MyProxyProperty
    {
        get {return SplitCamelCase(MyRealProperty);}
        set {MyRealProperty = ConcatCamelCase(value);}
    }
}
于 2011-10-27T02:16:07.197 回答
-1

您可以使用 XMlSerialization 属性显式设置序列化的所有内容的名称。

[XmlRoot("theNameYouWant")]

[XmlElement("theNameYouWant")]
于 2011-10-26T23:32:32.463 回答