Last active
May 2, 2021 15:16
-
-
Save sgaliamov/bf2d391c2aad0d4f31dd29b966a992b0 to your computer and use it in GitHub Desktop.
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
| var method = new DynamicMethod("Foo", typeof(int), new[] { typeof(int) }); | |
| var generator = method.GetILGenerator(); | |
| var label = generator.DefineLabel(); | |
| var il = generator.UseIlluminator(); // Creates wrapper | |
| il.Ldarg_0() | |
| .Ldc_I4_2() | |
| .Ceq() | |
| .Brfalse_S(label) // if (value == 2) | |
| .Ldc_I4_1() | |
| .Ret() // return 1 | |
| .MarkLabel(label) | |
| .Ldarg_0() | |
| .Ldc_I4_3() | |
| .Add() | |
| .Ret(); // return value + 3 | |
| var foo = method.CreateDelegate<Func<int, int>>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment