【发布时间】:2021-09-23 20:22:36
【问题描述】:
我有
Type tsomething = /* ... */ ;
Type comparer = typeof(Func).MakeGenericType(new Type[]{tsomething, tsomething, int});
但编译器不喜欢未专门化的Func。有没有办法把这个拼出来,这样我就可以动态地专门化泛化类型。
我不能用直接专用的 Func 替换,因为我在编译时不知道自己的类型。涉及Reflection.Emit;试图写typeof(Func<something, something>, int) 是不可能的。
完全相同的结构出现在下面几行
il.DeclareLocal(typeof(IEnumerator).MakeGenericType(new Type[]{tsomething}));
【问题讨论】:
标签: c# reflection reflection.emit