Skip to content

Instantly share code, notes, and snippets.

View amywarble's full-sized avatar

Amy amywarble

View GitHub Profile
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