0

I have factory method that returns Type of a POCO given a Key.

    public static Type GetType(string key)
    {
        var name = string.format("MyPOCOClass{0},MyAssembly",key);
        return Type.GetType(name);
    }

So lets say value of the Key is One and assume that the class MyPOCOClassOneexists in MyAssembly

in above case i wanted type of IEnumerable<MyPOCOClassOne> How do i do that?

LP13
  • 30,567
  • 53
  • 217
  • 400

1 Answers1

1

You want to take advantage of Type.MakeGenericType(MSDN). In your case:

Type enumerable = typeof(IEnumerable<>); //Unresolved generic!
Type yourType = GetType(someKey); //OP Method

return enumerable.MakeGenericType(yourType);
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117