[英]ConstructorInfo of a function/delegate in F#
How is it possible to get the following CIL constructor in F# (as System.Relection.ConstructorInfo
)?如何在 F# 中获得以下 CIL 构造函数(作为System.Relection.ConstructorInfo
)?
[mscorlib]System.Func`3<int32,int32,int32>::.ctor(object, native int)
I have tried the following, but I get null:我尝试了以下方法,但得到 null:
typeof<int * int * int>.GetConstructor([|typeof<obj> ; typeof<nativeint>|]);;
val it : System.Reflection.ConstructorInfo = <null>
Also, is it possible to do it dynamically?另外,是否可以动态执行? Let's say instead of 3 int types, there is a random System.Type list
.假设不是 3 种 int 类型,而是随机的System.Type list
。 How?如何?
Found out:发现:
System.Linq.Expressions.Expression.GetDelegateType([|typeof<int> ; typeof<int> ; typeof<int>|]).GetConstructor([|typeof<obj> ; typeof<nativeint>|]).DeclaringType;;
The GetDelegateType
method takes an array of types, so it can be used dynamically. GetDelegateType
方法采用类型数组,因此可以动态使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.