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