PC Review


Reply
Thread Tools Rate Thread

IDbCommand.Parameters and Explict Interface Implementation

 
 
Simon
Guest
Posts: n/a
 
      7th Jun 2006
Hi All,

I wanted to inherit a new SQLCommand (mostly to set default and ensure
consistancy), but the class is NotInheritable, so instead I created a
class implementing IDbCommand.

So far so good. The problem I'm having is with the definition of the
parameters (specifically the return type). IDbCommand defines them as

public readonly property parameters() as
system.data.IDataParameterCollection Implements
Systen.Data.IDbCommand.Parameters

Whereas what I want to return is the usual
SqlClient.SqlParameterCollection for my derived classes. Seemingly
this is possible in C# via something called "Explicit Interface
Implentation" - a feature that seems to be missing from VB.NET (though
I accept that the VB interface model is more flexible).

If instead I wish to define

public readonly property Parameters() as
system.data.sqlclient.SqlParameterCollection

the compiler complains that the definitions cannot overload each other
because only the return types are different.

I presume that I can cast the IDataParameter version to a
SqlParamaterCollection in the derived classes but that's a departure
from normal practices and my goal here is to make things easier down
the line.

Has anyone come across this and how did you work around it? I've not
used interfaces extensively before so am more than happy to be told I'm
overlooking something.

 
Reply With Quote
 
 
 
 
Simon
Guest
Posts: n/a
 
      7th Jun 2006
Don't you hate it when you forget something?

I should add that the best solution that I've come up with so far is to
create an intermediary class that overrides the default behaviour of
Parameters and casts it to the SqlParameterCollection.

So I have


Base (implementing IDbCommand)
|
intermediary (overloads Parameters to return SqlParameterCollection)
|
derived classes

This seems to work fine,but isn't what you'd call elegant.

Simon wrote:
> Hi All,
>
> I wanted to inherit a new SQLCommand (mostly to set default and ensure
> consistancy), but the class is NotInheritable, so instead I created a
> class implementing IDbCommand.
>
> So far so good. The problem I'm having is with the definition of the
> parameters (specifically the return type). IDbCommand defines them as
>
> public readonly property parameters() as
> system.data.IDataParameterCollection Implements
> Systen.Data.IDbCommand.Parameters
>
> Whereas what I want to return is the usual
> SqlClient.SqlParameterCollection for my derived classes. Seemingly
> this is possible in C# via something called "Explicit Interface
> Implentation" - a feature that seems to be missing from VB.NET (though
> I accept that the VB interface model is more flexible).
>
> If instead I wish to define
>
> public readonly property Parameters() as
> system.data.sqlclient.SqlParameterCollection
>
> the compiler complains that the definitions cannot overload each other
> because only the return types are different.
>
> I presume that I can cast the IDataParameter version to a
> SqlParamaterCollection in the derived classes but that's a departure
> from normal practices and my goal here is to make things easier down
> the line.
>
> Has anyone come across this and how did you work around it? I've not
> used interfaces extensively before so am more than happy to be told I'm
> overlooking something.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementation of interface method is the same in all of the interface's implementations StevenECBrown@gmail.com Microsoft C# .NET 6 17th Mar 2007 12:44 AM
Re: Explict generic methods Ben Voigt Microsoft Dot NET Framework 0 9th Jan 2007 08:33 PM
Re: Explict generic methods Barry Kelly Microsoft Dot NET Framework 0 9th Jan 2007 07:17 PM
Cannot insert explict value for identity column in table 'Employees' when IDENTITY_INSERT is set to OFF." Christopher Lusardi Microsoft VB .NET 6 1st Jun 2006 05:28 AM
explict conversion from double to int - regarding overflow handling Felix Microsoft C# .NET 1 16th Aug 2004 11:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:13 PM.