IDbCommand.Parameters and Explict Interface Implementation

S

Simon

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.
 
S

Simon

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.
 

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