Generics, Type and typeof()

S

Stefan Hoffmann

hi @all,

I have the following interface declaration:

public interface IBaseDao<T> where T : BasePOJO
{
List<T> FindAll(Type entityClass);
}

The parameter entityClass should be typeof(T).

I thought of something like

List<T> FindAll(Type<T> entityClass);

but there is not such a generic for Type.

So, is this possible?


mfG
--> stefan <--
 
M

Marc Gravell

Can you clarify what it is you want to do? I can interpret that a few
different ways...

Perhaps if you indicate how you want to call it and what you want to happen?

Marc
 
K

kyle.szklenski

I agree with the first commenter that it's hard to understand what
you're trying to do.

Given what you've said, one possible interpretation says maybe this
would be what you're looking for:

public interface IBaseDao<T> where T : BasePOJO
{
List<T> FindAll(T entityClass);
}

Is that it, or do we just need more information?

Kyle
 
S

Stefan Hoffmann

hi Marc, Kyle,

I should have give you my actual case:

I'm trying to convert an interface from Jave to C#. In Jave it looks
like this:

public interface IBaseDAO<T extends BasePOJO>
{
List<T> findAll(Class<T> entityClass);
}

I found an Java guy, who explained it: it's basically a hack, as the
implementation looks like:

public List<T> findAll(Class<T> entityClass)
{
List<T> results = getHibernateTemplate().loadAll(entityClass);
return results;
}

It seems that they can't use

public List<T> findAll()
{
return GetHibernateTemplate().LoadAll(typeof(T));
}

as we can do in C#.

Thanks for your efforts.


mfG
--> stefan <--
 

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