473,414 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Help with desrialization of a concrete class

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

Nov 16 '05 #1
4 1273
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Julia" <co********@012.net.il> wrote in message
news:uk**************@TK2MSFTNGP10.phx.gbl...
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

Nov 16 '05 #2
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...

"Julia" wrote:
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

Nov 16 '05 #3
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.

"Julia" wrote:
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

Nov 16 '05 #4
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
}

"Daniel Jin" <Da*******@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
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.

"Julia" wrote:
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

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Julia | last post by:
Hi I have a domain model and I am looking for the correct design patterns to use, The following is my domain model Server-> the is the thread boundaries,the server create a thread the...
15
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that...
9
by: mead | last post by:
What kind of classes is qualified as "concrete classes"? When should a member function in a class defined as "pure virtual" and when as "virtual"? Thanks!
5
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I...
2
by: Wat | last post by:
Is it doable to have a abstract class derived from a concrete class? Is it a good practice? If so in what situation is this necessary? Thanks in advance!
9
by: Sacha | last post by:
I work on a rather large C++ project. The design, so far, seems to be fine. However, there is one class, where the number of methods (and less dramtically the number of members, too) is growing and...
4
by: Tarun Mistry | last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies to both (apologies if it breaks some group rules). I am making a web app in asp.net using c#. This is the first fully OO...
2
by: Chris | last post by:
Hi, I have been stuck trying to come up with a design for days. I am working on a small project regarding barcode and I want to implement a factory design. I am now confused. I decided factory...
4
by: dascandy | last post by:
Hi, For a project I'm working on I'm kind-of-hacking my way around deriving a class from an interface or such to create a mock, but instead creating the mock directly. It is usable as the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.