Last active
December 15, 2015 19:19
-
-
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.
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
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