Generics and static members

F

Filip Zawada

Hi,

I've encountered a rather interesting language problem. Suppose I've
got following types:

//class providing usefull static methods
public class GoodBase<T>
{
public static void Met(){};
}

public class SomeEntity
: GoodBase<SomeEntity>
{
}

public interface IDictModel<T>
where T : GoodBase<T>
{
}

public class DictModel<T>
: IDictModel<T>
where T : GoodBase<T>
{
public void Test()
{
GoodBase<SomeEntity>.Met(); //OK
SomeEntity.Met(); //OK
T.Met(); //won't compile
}
}

The question is why can't I call a static method using generic
parameter?

I've specified that T is of type GoodBase<T>, so static methods from
GoodBase should be available by using generic parameter... Isn't
GoodBase<SomeEntity>.Met() actually the same as T.Met()? Why do I have
to repeat myself?

Regards,
Filip Zawada
 
F

Filip Zawada

Thank you for the answer, Pete. It was very helpful.
Now as I know the reasons, it's so obvious.

Filip
 

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