动态创建类型

本文关键字:类型 创建 动态 | 更新日期: 2023-09-27 18:13:16

我有以下内容:typeof(Action<User, Int32>),我需要能够动态创建…

我有两个类型,我需要存储为Type对象。

Type type1 = ...; // MyNamespace.BusinessObjects.User
Type type2 = ...; // System.Int32
// I need it to be Action<MyNamespace.BusinessObjects.User, System.Int32>
Type action = ? ;

我不知道该怎么做。

动态创建类型

我想这应该行得通:

var actionType = typeof(Action<,>).MakeGenericType(type1,type2);