[英]ConstructorInfo of a function/delegate in F#
如何在 F# 中獲得以下 CIL 構造函數(作為System.Relection.ConstructorInfo
)?
[mscorlib]System.Func`3<int32,int32,int32>::.ctor(object, native int)
我嘗試了以下方法,但得到 null:
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
方法采用類型數組,因此可以動態使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.