0

I have a Generic class of T where T is a class i want to create an object from this Generic Class but I have Class name in string this my code

public class GenericClass<T>:IGeneric<T> where T : class
{
    public IEnumerable<T> Get
    {
        //Whatever The Logic Is
    }
}
Abdelrahman Hussien
  • 505
  • 2
  • 4
  • 17
  • What *is* your string? It surely must be something like `"GenericClass"`, is it? So please show the exact signature of your method you want. Be aware that as you provide `T` at runtime there´s no way to return an `IEnumerable` from your method. You can only return `IEnumerable`. Have you seen this: https://stackoverflow.com/questions/266115/pass-an-instantiated-system-type-as-a-type-parameter-for-a-generic-class/266282 – MakePeaceGreatAgain Nov 14 '17 at 10:44
  • I can create object easily if i know the class like `var g= new GenericClass()` but I get The class Name at the run time in a string format, like `string c="Employee"` – Abdelrahman Hussien Nov 14 '17 at 10:49
  • Then the duplicate is *exactly* what you should do. – MakePeaceGreatAgain Nov 14 '17 at 10:54

0 Answers0