[Mono-list] RE: System.Xml.Serialization.XmlSerializer
Urs Muff
umuff@quark.com
Thu, 30 Jan 2003 14:15:41 -0700
> Hello,
>
> > Does the mono implementation of System.Xml.Serialization.XmlSerializer
> allow
> > methods or properties to use interfaces? An interface and an abstract
> class
> > should work exchangeable but the Microsoft runtime does not allow
> interfaces
> > even when using the XmlElement(Type = typeof(someType)) attribute on
> that
> > property.
>
> ...Oops, your code didn't work well with current mono library.
> There must be something wrong with XmlSerializer class;-)
That's a shame :(, but at least we have a sample to fix it.
Who is working on the XmlSerializer again?
>
> IMHO, it it impossible to serialize instance fields because we cannot
> decide that interface field is of a public class, and we cannot create
> instance only from interface information (i.e. without any concrete
> class information). Hmm... I wonder how Castor handles such things...
Well first of all, why should [XmlInclude(typeof(S))] not work, since it
works on an abstract class that cannot be constructed as well. I'm a
compiler constructor myself, and would argue that an abstract class with
just abstract methods/properties and an interface should be very similar if
not equal.
At runtime the class of the property is known and it can be serialized as
such.
The output should still be, no matter if A is an abstract property or an
interface property, as long as "S" is inherited/implements that
class/interface:
<?xml version="1.0" encoding="utf-16"?>
<Sample xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<A xsi:type="S">
<val>a value</val>
</A>
</Sample>
>
> This page might informative for you:
> http://www.dotnet247.com/247reference/msgs/16/80980.aspx
Thanks a lot for that link. I already saw that, and hoped that the mono
implementation would be better.
- Urs