更新时间:2022-12-30 15:52:36
我认为您正在寻找 MakeGenericType
方法:
I think you're looking for the MakeGenericType
method:
// Assuming that Property.PropertyType is something like List<T>
Type elementType = Property.PropertyType.GetGenericArguments()[0];
Type repositoryType = typeof(GenericRepository<>).MakeGenericType(elementType);
var repository = Activator.CreateInstance(repositoryType);