Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Last active December 15, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcsjones/5310717 to your computer and use it in GitHub Desktop.
Save vcsjones/5310717 to your computer and use it in GitHub Desktop.
Determines with a rather naive way of determining at run time if a method is empty.
Action<int> gfa = k => { };
var il = gfa.Method.GetMethodBody().GetILAsByteArray().Where(b => b != OpCodes.Nop.Value).ToArray();
if (il.Length == 0 || (il.Length == 1 && il[0] == OpCodes.Ret.Value))
{
Debug.WriteLine("Empty!");
}
else
{
Debug.WriteLine("Not empty!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment