This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getFunctionName f = | |
let type' = f.GetType() | |
let method' = type'.GetMethods() |> Array.find (fun m -> m.Name="Invoke") | |
let il = method'.GetMethodBody().GetILAsByteArray() | |
let methodCodes = [byte OpCodes.Call.Value;byte OpCodes.Callvirt.Value] | |
let position = il |> Array.findIndex(fun x -> methodCodes |> List.exists ((=)x)) | |
let metadataToken = BitConverter.ToInt32(il, position+1) | |
let actualMethod = type'.Module.ResolveMethod metadataToken | |
sprintf "%s.%s" actualMethod.DeclaringType.FullName actualMethod.Name |
Unfortunately, this code only works when F# compiler does not inline function body into calling method.