let Sigmund () =
System.Reflection.MethodBase.GetCurrentMethod().Name
let Donald () =
System.Reflection.MethodBase.GetCurrentMethod().Name
let Eustachio () =
System.Reflection.MethodBase.GetCurrentMethod().Name
let get_name_of_x (x: unit -> unit) =
//System.Reflection.???
()
let x =
[|
Sigmund
Donald
Eustachio
|]
x |> Array.iter (fun x -> x() |> printfn "%s") // prints all the names
Since the functions can see their own name, I know it should be possible to get the name of the function passed into get_name_of_x
, but I can't figure out how. Having the ability to do this would be useful in writing my own testing library.
Fuchu for example does not strip names directly from functions, and using DUs for composition instead of functions makes it less flexible than it could be, so it might be worth improving on.
Aucun commentaire:
Enregistrer un commentaire