Created
February 9, 2012 19:23
-
-
Save ilkerde/1782233 to your computer and use it in GitHub Desktop.
Func<dynamic,bool> interplay between C# and F#
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
namespace FuncTest { | |
using System; | |
public class EmitBit { | |
public Func<dynamic,bool> Emitter { get; set; } | |
public void Emit() { | |
Console.WriteLine("emit was {0}", Emitter("test")); | |
} | |
} | |
} | |
/* | |
compiles to -> EmitBit.dll | |
*/ |
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
#r "EmitBit.dll" | |
open FuncTest | |
open System | |
let emitbit = new EmitBit() | |
let dynamicFunc = new Func<obj,bool>(fun o -> o.ToString() = "test") | |
let nullCheck = function | |
| null -> "is null" | |
| _ -> "has func" | |
emitbit.Emitter <- dynamicFunc | |
nullCheck emitbit.Emitter |> printfn "emitter %s" | |
emitbit.Emit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment