Re-implementing ISerializable.GetObjectData() on DataTable derived class

F

Frans Bouma

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 statement to VB.NET and this is
crucial: re-implementing ISerializable.GetObjectData() in the DataTable
derived class so serializing the datatable derived class will call this
method and not the DataTable version (which is private, so overriding is
also not possible)

It comes down to this:
1) I have a DataTable derived class. This class is implemented in VB.NET.
This class contains a private member.
2) I want to serialize and deserialize this class using Soap or Binary
formatter. The problem is the private member variable: because of this I
have to implement ISerializable.GetObjectData() because DataTable already
implements this method, but this method is Private, and if I don't
implement this method I can't serialize this membervariable because the
DataTable's GetObjectData() method will be called instead.
3) In C# I can solve this by re-implementing ISerializable.GetObjectData()
like:
void System.Runtime.Serialization.ISerializable.GetObjectData
(SerializationInfo info, StreamingContext context)
This will make sure that this implementation will be seen as the
implementation of ISerializable.GetObjectData(). I do the serialization of
the DataTable in here. Works ok in C#.

The problem is now: I can do something like:
Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
in VB.NET but that will not help me, because when serializing, this method
will not be called, simply because it is not seen as a
ISerializable.GetObjectData() implementation, so the DataTable version is
used, which is not what I want, because of the private member variable.

I also can't specify Implements ISerializable.GetObjectData() or other
ways to make sure this is a re-implementation of the interface member,
because the VB.NET compiler will then throw an error saying that the base
class already implements this interface and/or method.

My question is now: Is it possible to solve this in VB.NET? I couldn't
find any information which states how to re-implement interface members,
but perhaps I'm overlooking something.

Thanks in advance!

FB
 
J

Jay B. Harlow [MVP - Outlook]

Frans,
What you have stated is the way I understand VB.NET works, Once a class
implements an interface, base classes cannot re-implement them.

If you really need to do this, I would recommend a C# base class that you
use to "re-implement" ISerializable.GetObjectData. You can then derive from
this class in VB.NET do what you are attempting.

Hope this helps
Jay
 
F

Frans Bouma

Frans,
What you have stated is the way I understand VB.NET works, Once a class
implements an interface, base classes cannot re-implement them.

I was afraid of that... :(
If you really need to do this, I would recommend a C# base class that
you use to "re-implement" ISerializable.GetObjectData. You can then
derive from this class in VB.NET do what you are attempting.

I think that's the only solution to this indeed. Requires some
refactoring though ... :/ I hope VB.NET's designers will solve this in
Whidbey.

Thanks for the info.

FB
 
J

Jay B. Harlow [MVP - Outlook]

Frans,
I hope VB.NET's designers will solve this in
Whidbey.
I'm not so sure VB.NET is "broken" per se here.

You could always submit an MS Wish to have the current behavior changed.

http://register.microsoft.com/mswish/suggestion.asp

Jay

Frans Bouma said:
I was afraid of that... :(


I think that's the only solution to this indeed. Requires some
refactoring though ... :/ I hope VB.NET's designers will solve this in
Whidbey.

Thanks for the info.

FB
<<snip>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top