c# Creating an unknown generic type at runtime

前端 未结 2 1119
时光取名叫无心
时光取名叫无心 2020-11-30 11:44

So I have a class that is a generic and it may need to, inside a method of its own, create an instance of itself with a different kind of generic, whose type is obtained thr

2条回答
  •  伪装坚强ぢ
    2020-11-30 12:02

    Activator.CreateInstance(typeof(GenericRepository<>).MakeGenericType(new Type[] { Property.GetTYpe() }))
    

提交回复
热议问题