Skip to main content
added 288 characters in body
Source Link
Ishan Arora
  • 324
  • 2
  • 17

I have a generic Class

public  class MyClass<T>
{
   public List<T> Translate(List<T> list, params string[] names)
           {
            //Somedo methodsomething here,modify list and return list
       }
    }

Now i can easily create its instances like

MyClass<Employee> obj= new MyClass<Employee>(); OR
MyClass<Vehicle> obj = new MyClass<Vehicle>();

I can call my method like

    obj.Translate(Mylist of employee or vehicle type,"param1","param2")

But in my case i dont know the type T as its generated on runtime,see the code below

String classname = string.Empty;

if(Classtype == 1)
{
    classname = "Employee"
}
else if(classtype == 2)
{
    classname = "Vehicle"
}
    

I want something like below..so that i can creat an instance of this generic class

MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>(); 

    empp.Translate(MyList,"param1","param2")

Please suggest,how can i do that.

I have a generic Class

public  class MyClass<T>
{
  //Some method 
}
    

Now i can easily create its instances like

MyClass<Employee> obj= new MyClass<Employee>();
MyClass<Vehicle> obj = new MyClass<Vehicle>();
    

But in my case i dont know the type T as its generated on runtime,see the code below

String classname = string.Empty;

if(Classtype == 1)
{
    classname = "Employee"
}
else if(classtype == 2)
{
    classname = "Vehicle"
}
    

I want something like below..so that i can creat an instance of this generic class

MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>();
    

Please suggest,how can i do that.

I have a generic Class

public  class MyClass<T>
{
   public List<T> Translate(List<T> list, params string[] names)
           {
            //do something here,modify list and return list
       }
    }

Now i can easily create its instances like

MyClass<Employee> obj= new MyClass<Employee>(); OR
MyClass<Vehicle> obj = new MyClass<Vehicle>();

I can call my method like

    obj.Translate(Mylist of employee or vehicle type,"param1","param2")

But in my case i dont know the type T as its generated on runtime,see the code below

String classname = string.Empty;

if(Classtype == 1)
{
    classname = "Employee"
}
else if(classtype == 2)
{
    classname = "Vehicle"
}
    

I want something like below..so that i can creat an instance of this generic class

MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>(); 

    empp.Translate(MyList,"param1","param2")

Please suggest,how can i do that.

formatting
Source Link
Panu Haaramo
  • 2.9k
  • 23
  • 43

I have a generic Class

public  class MyClass<T>
{
  //Some method 
}
    

Now i can easily create its instances like

MyClass<Employee> obj= new MyClass<Employee>();
MyClass<Vehicle> obj = new MyClass<Vehicle>();
    

But in my case i dont know the type T as its generated on runtime,see the code below

String classname = string.Empty;

if(Classtype == 1)
{
    classname = "Employee"
}
else if(classtype == 2)
{
    classname = "Vehicle"
}
    

I want something like below..so that i can creat an instance of this generic class

MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>();
    

Please suggest,how can i do that.

Regards ishan

I have a generic Class

public  class MyClass<T>
{
  //Some method 
}
    

Now i can easily create its instances like

MyClass<Employee> obj= new MyClass<Employee>();
MyClass<Vehicle> obj = new MyClass<Vehicle>();
    

But in my case i dont know the type T as its generated on runtime,see the code below

String classname = string.Empty;

if(Classtype == 1)
{
    classname = "Employee"
}
else if(classtype == 2)
{
    classname = "Vehicle"
}
    

I want something like below..so that i can creat an instance of this generic class

MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>();
    

Please suggest,how can i do that.

Regards ishan

I have a generic Class

public  class MyClass<T>
{
  //Some method 
}
    

Now i can easily create its instances like

MyClass<Employee> obj= new MyClass<Employee>();
MyClass<Vehicle> obj = new MyClass<Vehicle>();
    

But in my case i dont know the type T as its generated on runtime,see the code below

String classname = string.Empty;

if(Classtype == 1)
{
    classname = "Employee"
}
else if(classtype == 2)
{
    classname = "Vehicle"
}
    

I want something like below..so that i can creat an instance of this generic class

MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>();
    

Please suggest,how can i do that.

I have a generic Class

    public  class MyClass<T>
        {
          //Some method 
        }
    

Now i can easily create its instances like

                MyClass<Employee> obj= new MyClass<Employee>();
                MyClass<Vehicle> obj = new MyClass<Vehicle>();
    

But in my case i dont know the type T as its generated on runtime,see the code below

    String classname = string.Empty;
    
    if(Classtype == 1)
    {
        classname = "Employee"
    }
    else if(classtype == 2)
    {
        classname = "Vehicle"
    }
    

I want something like below..so that i can creat an instance of this generic class

    MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>();
    

Please suggest,how can i do that.

Regards ishan

I have a generic Class

    public  class MyClass<T>
        {
          //Some method 
        }
    

Now i can easily create its instances like

                MyClass<Employee> obj= new MyClass<Employee>();
                MyClass<Vehicle> obj = new MyClass<Vehicle>();
    

But in my case i dont know the type T as its generated on runtime,see the code below

    String classname = string.Empty;
    
    if(Classtype == 1)
    {
        classname = "Employee"
    }
    else if(classtype == 2)
    {
        classname = "Vehicle"
    }
    

I want something like below..so that i can creat an instance of this generic class

    MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>();
    

Please suggest,how can i do that.

Regards ishan

I have a generic Class

public  class MyClass<T>
{
  //Some method 
}
    

Now i can easily create its instances like

MyClass<Employee> obj= new MyClass<Employee>();
MyClass<Vehicle> obj = new MyClass<Vehicle>();
    

But in my case i dont know the type T as its generated on runtime,see the code below

String classname = string.Empty;

if(Classtype == 1)
{
    classname = "Employee"
}
else if(classtype == 2)
{
    classname = "Vehicle"
}
    

I want something like below..so that i can creat an instance of this generic class

MyClass<typeof(classname)> empp = new MyClass<typeof(classname)>();
    

Please suggest,how can i do that.

Regards ishan

Source Link
Ishan Arora
  • 324
  • 2
  • 17
Loading