Skip to content

Instantly share code, notes, and snippets.

@jbevain
Created December 20, 2013 16:00
Show Gist options
  • Select an option

  • Save jbevain/8056846 to your computer and use it in GitHub Desktop.

Select an option

Save jbevain/8056846 to your computer and use it in GitHub Desktop.
Consuming a reflection type provider.
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