G
Guest
Hi all - I'm sure I'm being brain-dead here - and I think the answer is 'you
can't do that', but I thought I would try.
I have an interface that is Generic, with two type arguments. I want to
create a second interface that specifices the second type argument. I also
want to have objects implement that second interface without having to
implement the more generic methods that are inherited from the first. This
is especially evident when I implement multiple interfaces:
Some code will illustrate the problem:
// Base Type
interface I
{}
// 'Base' manager
interface IBase<T1, T2> where T2 : ICollection<T1>
{
T2 GetT1s();
}
// Base type collection
interface ICol<T1> : ICollection<T1> where T1 : I {}
// Derived type
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I {}
// Actual entities to manage
class A : I {}
class B : I {}
// Manager
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// Note the explicit implementation here
ICol<B> IBase<B, ICol<B>>.GetT1s()
{...}
}
I would really like to get rid of the 'IBase<B, ICol<B>>' - I would like to
use IDerived<B>, but this doesn't work. if I change IDerived to look like
this:
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I
{ new ICol<T1> GetT1s();}
Then I need to implement two forms of the method in the manager:
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// I want the following method...
ICol<B> IDerived<B>.GetT1s()
{...}
// But not this one!
ICol<B> IBase<B, ICol<B>>.GetT1s()
{...}
}
What am I doing wrong? I would love to only have to implement
IDerived<B>.GetT1s();
Thanks,
Phil
can't do that', but I thought I would try.
I have an interface that is Generic, with two type arguments. I want to
create a second interface that specifices the second type argument. I also
want to have objects implement that second interface without having to
implement the more generic methods that are inherited from the first. This
is especially evident when I implement multiple interfaces:
Some code will illustrate the problem:
// Base Type
interface I
{}
// 'Base' manager
interface IBase<T1, T2> where T2 : ICollection<T1>
{
T2 GetT1s();
}
// Base type collection
interface ICol<T1> : ICollection<T1> where T1 : I {}
// Derived type
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I {}
// Actual entities to manage
class A : I {}
class B : I {}
// Manager
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// Note the explicit implementation here
ICol<B> IBase<B, ICol<B>>.GetT1s()
{...}
}
I would really like to get rid of the 'IBase<B, ICol<B>>' - I would like to
use IDerived<B>, but this doesn't work. if I change IDerived to look like
this:
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I
{ new ICol<T1> GetT1s();}
Then I need to implement two forms of the method in the manager:
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// I want the following method...
ICol<B> IDerived<B>.GetT1s()
{...}
// But not this one!
ICol<B> IBase<B, ICol<B>>.GetT1s()
{...}
}
What am I doing wrong? I would love to only have to implement
IDerived<B>.GetT1s();
Thanks,
Phil