Thanks Silky, I've left the members from ILevel1 out of this example as
it added nothing to the example. I've explicitly called the function for
now respecifying T and E so it works, I just think it's ugly. The Level1
class is trying to hide the required knowledge of T and E from the
caller, they just know that they need a Level of type ILevel1 and the
factory works out which one.

Anyway, thanks for the input.
Clint

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of silky
Sent: Thursday, 4 November 2010 10:10 AM
To: ozDotNet
Subject: Re: It's a question of Generics...

On Thu, Nov 4, 2010 at 10:25 AM, Clint Colefax
<[email protected]> wrote:
> Just playing around with some generics, and I'm getting one bit that
I'm not
> happy with. I thought I had this working, but I've changed something
and now
> it doesn't.
>

> I have an interface
>
> Interface IBase(Of T, E)
>
>
> And a child interface
>
> Interface ILevel1
>
> And a Class
>
> Class Level1
>                 Implements ILevel1
>                 Implements IBase(of string, integer)
>
> Then I have a factory with a method as such
>
> Function GetALevel(Of TLevel(Of T, E)() As IBase(Of T, E)
>
> In another class, I want to call the following
>
> Dim foo as Factory = new Factory
> Dim bar as foo.GetALevel(Of ILevel1)()
>
> I think that the type of T and E should be inferred from the ILevel
> interface.

How? The ILevel interface, as posted, doesn't implement anything?

It seems like you want to do something like (C#):


                public static IBase<X, A> GetALevel<T>()
                        where T : IBase<X, A>
                {
                        return null;
                }

But, that doesn't compile, because X and A aren't specified anywhere.
You need to "get" those types, at compile time, from the parameters
passed to the GetALevel(ILevel)

I'm just not so sure that's possible.

Maybe it is. I don't know. I agree it seems redundant to have to
specify the types that ILevel (assuming you mean for that to inherit
IBase with the appropriate types set) has. But I don't see how you can
make the return type of that method a generic IBase without getting
the types from the parameter (directly).

Hopefully someone else has some more useful comments.


> I'm sure I had this working, then a made a number of changes all
> around this code, then noticed it wasn't working anymore.
>
> Can anyone explain this better?
>
> Thanks
>
> Clint Colefax

-- 
silky

http://dnoondt.wordpress.com/

"Every morning when I wake up, I experience an exquisite joy - the joy
of being this signature."

Reply via email to