473,399 Members | 3,656 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,399 software developers and data experts.

Implementing IPersistStream using .Net Serialization

I have a .Net class (a collection) that already supports serialization.
It implements ISerializable...

Now, I need it to also support the COM interface IPersistStream. Among
other things, I need to be able to pass instances of this class to
methods of queued components (in COM+).

I want to "piggy back" my implementation of IPersistStream to what is
already being used for serialization. So, in the Save() method of
IPersistStream, the object serializes itself using the BinaryFormatter
and writes it to the given stream.

The problem is in the Load() method, I cannot figure out how to make
the object take the given stream and deserialize itself "in place".

Am I missing something?

Nov 17 '05 #1
2 2621
You could introduce a second class, which implements IPersistStream. In the
Save and Load methods of this class, you could just use standard
de/serialization code to persist/create instances of your main class.

HTH,
Mark

<re****@gmail.com> schrieb im Newsbeitrag
news:11**********************@o13g2000cwo.googlegr oups.com...
I have a .Net class (a collection) that already supports serialization.
It implements ISerializable...

Now, I need it to also support the COM interface IPersistStream. Among
other things, I need to be able to pass instances of this class to
methods of queued components (in COM+).

I want to "piggy back" my implementation of IPersistStream to what is
already being used for serialization. So, in the Save() method of
IPersistStream, the object serializes itself using the BinaryFormatter
and writes it to the given stream.

The problem is in the Load() method, I cannot figure out how to make
the object take the given stream and deserialize itself "in place".

Am I missing something?

Nov 17 '05 #2
Thanks for your help...

Your suggestion is not ideal since it would have required me to change
the signature of the methods that accept my class as a parameter to the
wrapper class that you suggest whenever that method need an
"IPersistStream-able" object.

But your suggestion gave me the idea that my class should wrap the
implementation class that I used as a data member instead of inheriting
from it. This way, I can deserialize the data member and won't need to
deserialize to "this" which doesn't seem to be possible right now. This
will require more work and is not as clean but I think it will work.

This still begs the question on why the serialization framework in .net
does not allow deserialization to this or self. Maybe this can be done
by overloading the Deserialize method on IFormatter to accept a
reference to the object where the stream should be deserialized:

// existing method
object Deserialize(Stream deserializationStream);
// suggested new method
void Deserialize(Stream deserializationStream, ref object graph);

With the new method, one can deserialize in place:

formatter.Deserialize(stream, this);

This may also mean adding a method to ISerializable that does the
reverse of GetObjectData() which should be aptly named SetObjectData().
Unless the serialization framework can call the (usually protected)
contructor that accepts (SerializationInfo info, StreamingContext
context) on an already existing object.

Is it too late for this?
Mark Rockmann wrote:
You could introduce a second class, which implements IPersistStream. In the
Save and Load methods of this class, you could just use standard
de/serialization code to persist/create instances of your main class.

HTH,
Mark

<re****@gmail.com> schrieb im Newsbeitrag
news:11**********************@o13g2000cwo.googlegr oups.com...
I have a .Net class (a collection) that already supports serialization.
It implements ISerializable...

Now, I need it to also support the COM interface IPersistStream. Among
other things, I need to be able to pass instances of this class to
methods of queued components (in COM+).

I want to "piggy back" my implementation of IPersistStream to what is
already being used for serialization. So, in the Save() method of
IPersistStream, the object serializes itself using the BinaryFormatter
and writes it to the given stream.

The problem is in the Load() method, I cannot figure out how to make
the object take the given stream and deserialize itself "in place".

Am I missing something?


Nov 17 '05 #3

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

Similar topics

2
by: reycri | last post by:
I have a .Net class (a collection) that already supports serialization. It implements ISerializable... Now, I need it to also support the COM interface IPersistStream. Among other things, I need...
1
by: J Askey | last post by:
Is this object available in Access? If so, what do I need to set a reference to? My bigger picture is needing a way to take a .bmp out of a SQL database and put into both an CommandBarButton...
1
by: Eric Workman | last post by:
Hi Everyone- I would like to implement the IFormatter class to create a custom formatter that essentially does exactly what the System.Xml.Serialization.XmlSerializer does, but also would allow...
3
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I...
2
by: Chris Puncher | last post by:
Hi. I have a RCW class that was generated by the VS.NET2003 IDE when I added a COM dll reference to my project. This all works fine when I call methods on it. My initial problem is that in...
3
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one...
3
by: Robin Tucker | last post by:
Does anyone have a VB.NET IPersistStream COM interface description I can cadge please? If I remember rightly, you have to "flatten" inherited COM interfaces (I think IPersistStream derives from...
0
by: =?Utf-8?B?Y2luZHk=?= | last post by:
I know I wrote before a week ago when I knew even less than now but I am getting better please anyone give me a clue or an example. Am I completely off track? I have a datarow in a table with the...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.