locked
IEnumerable for a System.Type RRS feed

  • Question

  • I have System.Type variable called customType and want to create a IEnumerable<> for that

    IEnumerable<customType> is giving an error ?

    How do I solve this

    Tuesday, June 25, 2013 12:45 PM

Answers

  • Typegeneric=typeof(List<>);
    Typespecific=generic.MakeGenericType(type);
    ConstructorInfoci=specific.GetConstructor(Type.EmptyTypes);
    objecto=ci.Invoke(newobject[] {});    

    See this: stackoverflow.com/questions/513952/specifying-generic-collection-type-param-at-runtime  
    • Proposed as answer by CoolDadTx Tuesday, June 25, 2013 2:08 PM
    • Marked as answer by Jason Dot Wang Monday, July 8, 2013 8:34 AM
    Tuesday, June 25, 2013 1:54 PM