gpt4 book ai didi

c# - 动态创建类型

转载 作者:行者123 更新时间:2023-11-30 15:06:17 24 4
gpt4 key购买 nike

我有以下内容: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);

关于c# - 动态创建类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8000165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com