Help with desrialization of a concrete class

  • Thread starter Thread starter Julia
  • Start date Start date
J

Julia

Hi,

I have a EmailMessage and a UrgentMessage objects both derived from IMessage
i also have BadMedia and GoodMedia objects both derived from IMedia

GoodMedia:IMedia
string Subject
string Body

BadMedia:IMedia
string Fine

the IMessage interface is as follows:

IMesssage
{
IMedia Media();
}

The problem is that the type of concrete Message to be create stored in
the XML document.
I would like to avoid parsing the document before desrialization


<Messsage type='EmailMessage'/>
<Media type="GoodMedia'>
<Subject></>
<Body></>
</Media>
</Messsage>


<Messsage type='UrgentMessage'/>
<Media type="BadMedia'>
<Fine></>
</Media>
</Messsage>


Thanks
 
Julia,

It appears you are doing some sort of custom XML serialization.
Honestly, what I would do in this case is use the SoapFormatter for this
kind of structure, and then create an XSLT transformation that will give you
the output that you want (you could even go back the other way).

Hope this helps.
 
Just a tip - if you make an *interface* implement ISerializable, then any
class that implements that interface, has to also implement ISerializable by
implication.

e.g.
interface IMedia : ISerializable
{
}
class GoodMedia : IMedia
{
public void GetObjectData(SerializationInfo info, StreamingContext context)
{ //has to have this method, from ISerializable.
}
}


Just a suggestion...
 
try the XmlIncludeAttribute to specify the derived classes. I've used it
successfully with the same base class, not sure if it will work with the same
base interface though.
 
Thanks.

Can the concrete Media be in a different assembly When desrialize a
Message?

----------------------------------------------------------------------------
-------------------------------------

IMesssage
{
IMedia Media;
}

GoodMedia:IMedia
string Subject
string Body

BadMedia:IMedia
string Fine

class Message:IMessage
{
IMedia media
}
 
Back
Top