1
Reply

Generic type as string name

purusingh

purusingh

Nov 9 2010 2:09 PM
10.7k

 
I don't know how to phrase my question.
I have Calss with Generic type. 
I.E.
<Code>
public calss EntMgr<T> where T: EntityObject
{
               public  T Get() {
                  return  context.CreateQuery(typeof(T).Name).ToList<T>();
               }
}
</Code>
 
Now in  I want to use that class from another class where I pass the Generectype as a string Value.
I.e.
<Code>
public class Proxy{
    public EntityObject Get(string entityObject)
{
     Type type = Type.GetType(entityObject);
      EntMgr<type> emr = new EntMgr<type>();
      emr.get();
}
 
</Code>
 
This doesn't work .
Is there a way to do something like that?
I know it is possible to work with "Activator"
But it creates unnecessary object.

Answers (1)