Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

Serialization of objects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flack - 11 Jan 2008 18:18 GMT
Hey guys,
Lets say I have an object, MyObject, that has a couple of public properties.
I want to serialize this object and include it in a larger xml message.  So,
I have some elements in the xml message that have nothing to do with the
object, whose values are retrieved elsewhere, and some values which are
gotten directly from MyObject.

All of the serialization examples I have seen deal with simply serializing
the entire object to its own xml format.  Any suggestions on how to achieve
what I described?

Here is an example of what I am trying to achieve:
- MyObject has properties Name and Count.
- SessionID is an ID which is not stored in the object.
The xml I am looking to create is:
<Request>
<SessionID>12345</SessionID>
<ObjectValues>
  <Name>Test</Name>
  <Count>2</Count>
</ObjectValues>
</Request>

Notice how the object type, MyObeject, is not used in the xml and that the
root name is also not related to the object.  Basically, the info in the
object just needs to be used.  Do I have to create such xml manually, using
an XmlWriter?  I was hoping there was some way I can define what info from
what source should be used when creating the xml.

Thanks.
Bob Powell [MVP] - 12 Jan 2008 13:36 GMT
In serialization, objects are responsible for their own encoding and
decoding. The serialization system in .NET is designed to enable an object
to persist itself fully.

If your properties require serialization they must be able to manage their
own encoding and decoding which may mean creating custom XML serialization
to satisfy your requirements.

Alternatively, you can use a Memento pattern implementation that provides an
object which creates a serialization stream on behalf of the object being
encoded.

Signature

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

> Hey guys,
> Lets say I have an object, MyObject, that has a couple of public
[quoted text clipped - 30 lines]
>
> Thanks.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.