-
-
Save amywarble/12415fdebcf7760f89b66b3b2d3a4abd to your computer and use it in GitHub Desktop.
This file contains 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
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