F#

问题描述

如何在F#中获得以下CIL构造函数(如System.Relection.ConstructorInfo)?

[mscorlib]System.Func`3<int32,int32,int32>::.ctor(object,native int)

我尝试了以下操作,但没有得到结果:

typeof<int * int * int>.GetConstructor([|typeof<obj> ; typeof<nativeint>|]);;
val it : System.Reflection.ConstructorInfo = <null>

还可以动态地进行吗?假设不是3个int类型,而是随机的System.Type list。怎么样?

解决方法

发现:

System.Linq.Expressions.Expression.GetDelegateType([|typeof<int> ; typeof<int> ; typeof<int>|]).GetConstructor([|typeof<obj> ; typeof<nativeint>|]).DeclaringType;;

GetDelegateType方法采用类型数组,因此可以动态使用。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...