F # Interactive Services: How to Transfer .NET Objects from the Host

I use F # CompilerServices to host the .NET scripting environment in my application, as here:

https://github.com/fsharp/FSharp.Compiler.Service/blob/master/samples/InteractiveService/Program.fs

If I evaluate expression ( EvalExpression), the data is sorted back to the host application, but there is no obvious way to pass the data in the opposite direction.

How to pass .NET objects from a host application to a script environment?

+4
source share
1 answer

This would be a great addition to the API provided by F # Interactive!

, , F #:

let parameters = new System.Collections.Generic.Dictionary<string, obj>()

EvalExpression , :

(fun k v -> parameters.Add(k, v))

string -> obj -> unit , , .

. - , , . F # .NET-, . , parameters ( ).

:

fsiSession.EvalInteraction
  ("let env = new System.Collections.Generic.Dictionary<string, obj>()")
fsiSession.EvalExpression
  ("System.Action<string, obj>(fun k v -> env.Add(k, v))")
+3
source

All Articles