简体   繁体   中英

ConstructorInfo of a function/delegate in F#

How is it possible to get the following CIL constructor in F# (as System.Relection.ConstructorInfo )?

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

I have tried the following, but I get 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM