Skip to content

Instantly share code, notes, and snippets.

@amywarble
Forked from mgravell/bools be cray cray
Created May 24, 2019 14:01
Show Gist options
  • Save amywarble/12415fdebcf7760f89b66b3b2d3a4abd to your computer and use it in GitHub Desktop.
Save amywarble/12415fdebcf7760f89b66b3b2d3a4abd 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