开发者

Custom type as XMLAttribute

开发者 https://www.devze.com 2023-02-27 02:35 出处:网络
I have a custom struct type that supports implicit conversion to and from string. I can serialize this struct as an element without any problems with the using the XmlText attribute on a public proper

I have a custom struct type that supports implicit conversion to and from string. I can serialize this struct as an element without any problems with the using the XmlText attribute on a public property.

struct Test
{
    [XmlText]
    public string Value {get(...);set(...);}
}

class Other
{
    [XmlElement] // this renders as <TestElemen开发者_运维知识库t>value</TestElement>
    public Test TestElement {get; set;} 

    [XmlAttribute] // this fails at runtime
    public Test TestElement {get; set;} 
}

However, I cannot serialize it as an attribute. Is there anyway to make it work?


[XmlText] means to serialize the data as the text value of an element. It cannot be used for an attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消