Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reflection 使用反射获取模块的所有let绑定_Reflection_F# - Fatal编程技术网

Reflection 使用反射获取模块的所有let绑定

Reflection 使用反射获取模块的所有let绑定,reflection,f#,Reflection,F#,我试图获取F#模块的所有let绑定字段,但我一直在努力 System.Reflection.Assembly.GetExecutingAssembly().GetTypes() |> Seq.collect(fun t -> t.GetFields()) 但它似乎没有返回绑定。(代码缩写,类型仅为模块)假设您只需要let绑定,而不需要模块内定义的任何类型,则可以对模块类型成员使用以下筛选器: open System.Reflection open System.Runtime.Co

我试图获取F#模块的所有let绑定字段,但我一直在努力

System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
|> Seq.collect(fun t -> t.GetFields())

但它似乎没有返回绑定。(代码缩写,类型仅为模块)

假设您只需要
let
绑定,而不需要模块内定义的任何类型,则可以对模块类型成员使用以下筛选器:

open System.Reflection
open System.Runtime.CompilerServices

module Test =
    type Marker = interface end

    let x = 3

    let f x = x * x

    let m = List.map


let moduleType = typeof<Test.Marker>.DeclaringType

moduleType.GetMembers()
|> Array.filter (fun m -> m.DeclaringType = moduleType)
|> Array.filter (fun m -> m.IsDefined(typeof<CompilerGeneratedAttribute>, true) |> not)
|> Array.filter (fun m -> m.MemberType <> MemberTypes.NestedType)
|> Array.map (fun m -> m.Name)
开放系统。反射
open System.Runtime.CompilerServices
模块测试=
类型标记=接口端
设x=3
设fx=x*x
设m=List.map
设moduleType=typeof.DeclaringType
moduleType.GetMembers()
|>Array.filter(fun m->m.DeclaringType=moduleType)
|>Array.filter(fun m->m.IsDefined(typeof,true)|>not)
|>Array.filter(趣味m->m.MemberType MemberTypes.NestedType)
|>Array.map(fun m->m.Name)
这将返回给您:
[|“f”;“m”;“x”|]