Hi Chris,
I'm shocked that the XmlSerializer doesn't support serializing an object as
an attribute value. I just tried it myself with a TypeConverter, implicit
and explicit operator overloads and ToString but nothing worked.
The runtime-error as well as the documentation for XmlAttributeAttribute
states that, ~ "XmlAttributeAtttribute and XmlTextAttribute cannot be used
to serialize complex types". Apparently that means TypeConverter, operator
overloads and the value of ToString() are all ignored by XmlSerializer. I
consider this a design flaw in the XmlSerializer class. At least one of the
aforementioned methods of Type conversion, preferably the TypeConverter,
should be used by the XmlSerializer.
- Dave
<ch***************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I have the following situation
class A
{
public class B
{
int serlize;
public int Serlize
{
get {...} set {...}
}
}
private B somthing;
[XmlAttribute("B")]
public B Somthing { get{...} set{...} }
}
I serlizie and it bombs. What I would like ideally is:
<A B="0" />
In my case B is a highly complex class but it can serialize to a very
simple construct such as an integer as above. I would like to avoid
having to write a property just so I can serialize in this manner. I am
trying to develop these classes as an API within a DLL, and I would
like the interface to have as few redundancies as possible to ensure
that it is not overly complex.