Custom type as XMLAttribute
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.
精彩评论