473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IDbCommand.Parameters and Explict Interface Implementation

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.

Jun 7 '06 #1
1 2702
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.


Jun 7 '06 #2

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

Similar topics

5
by: BoonHead, The Lost Philosopher | last post by:
Does anyone know how to implement internal interface documentation for functions and parameters? I found a similair thing for proerties. For properties I found something like:...
14
by: | last post by:
Hi, I was performing SQL UPDATE queries and I notice that they SUCCEED on the ExecuteNonQuery() call with NO exceptions raised BUT they fail at the Database. They say they succeed in the code...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
2
by: David O | last post by:
I am using the CRTP (Curiously Recurring Template Pattern) to provide a set of low-level functions customizable by environment. Using CRTP ensures that all the function have the same signatures,...
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
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...
1
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
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.