By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.GetObje ctData
(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

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
"Frans Bouma" <pe******************@xs4all.nl> wrote in message
news:Xn*********************************@207.46.24 8.16...
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.GetObje ctData
(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

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com

Nov 20 '05 #2

P: n/a
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
news:#L**************@TK2MSFTNGP11.phx.gbl:
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

Hope this helps
Jay
"Frans Bouma" <pe******************@xs4all.nl> wrote in message
news:Xn*********************************@207.46.24 8.16...
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.GetObje ctData
(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

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com



--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
Nov 20 '05 #3

P: n/a
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" <pe******************@xs4all.nl> wrote in message
news:Xn*********************************@207.46.24 8.16... "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
news:#L**************@TK2MSFTNGP11.phx.gbl:
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

Hope this helps
Jay

<<snip>>
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.