【发布时间】:2015-06-18 10:00:33
【问题描述】:
我可以编写一个函数,返回作为参数给出的函数的名称吗?
let funName f: string =
// returns the name of f.
例如,如果我将 printfn 作为参数传递给 funName,它会返回“printfn”。
> funName printfn;;
val it : string = "printfn"
编辑:我想编写一个函数doc,它返回与给定函数关联的 XML 文档。
let doc f = // returns the XML documentation of the function `f`.
要使用NuDoq 之类的内容检索函数的摘要,我想知道函数的名称。
【问题讨论】:
-
你到底想在这里实现什么 - 在 F# 中使用 currying 这可能很复杂。
-
可能类似于CallerMemberNameAttribute? OP 可能已经看到了这一点,但我会作为注释添加(参见 Nikon the Third 评论)。
标签: reflection f#