Created
December 20, 2013 16:00
-
-
Save jbevain/8056846 to your computer and use it in GitHub Desktop.
Consuming a reflection type provider.
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
| open System | |
| open System.Reflection | |
| open System.Reflection.Emit | |
| open SyntaxTree.Reflection | |
| let corlib = Assemblies.mscorlib | |
| let console = corlib.``System.Console`` | |
| let writeLine = console.``WriteLine(string)`` | |
| let write = DynamicMethod("write", null, [| typeof<string> |]) | |
| let il = write.GetILGenerator() | |
| il.Emit(OpCodes.Ldarg_0) | |
| il.Emit(OpCodes.Call, writeLine) | |
| il.Emit(OpCodes.Ret) | |
| let w = write.CreateDelegate(typeof<Action<string>>) :?> Action<string> | |
| w.Invoke("Hello beautiful world") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment