Pass An Instantiated System.Type as a Type Parameter for a Generic Class

后端 未结 6 1267
萌比男神i
萌比男神i 2020-11-21 07:46

The title is kind of obscure. What I want to know is if this is possible:

string typeName = ;
Type myType = Type.GetType(         


        
6条回答
  •  萌比男神i
    2020-11-21 08:07

    Unfortunately no there is not. Generic arguments must be resolvable at Compile time as either 1) a valid type or 2) another generic parameter. There is no way to create generic instances based on runtime values without the big hammer of using reflection.

提交回复
热议问题