Skip to content

Instantly share code, notes, and snippets.

@ntr
Last active August 29, 2015 14:02
Getting function name
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment