Skip to content

Instantly share code, notes, and snippets.

@mgravell
Last active May 24, 2019 14:01
Show Gist options
  • Save mgravell/c841f2a208eb8dcfb7a91f9ae6078a55 to your computer and use it in GitHub Desktop.
Save mgravell/c841f2a208eb8dcfb7a91f9ae6078a55 to your computer and use it in GitHub Desktop.
static async Task Main()
{
var dm = new DynamicMethod("evil", typeof(bool), new[] { typeof(int) });
var il = dm.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);
var func = (Func<int, bool>)dm.CreateDelegate(typeof(Func<int, bool>));
Console.WriteLine(func(0)); // false
Console.WriteLine(func(1)); // true
Console.WriteLine(func(2)); // true
Console.WriteLine(func(1) == func(2)); // false
Console.WriteLine(func(1) & func(2)); // false
Console.WriteLine(func(1) && func(2)); // true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment