Closed iotalambda closed 1 year ago
Hi @iotalambda,
You can do something like this:
dynamic setupConsole = engine.Evaluate("impl => console = { log: arg => impl.WriteLine(arg) }");
setupConsole(typeof(Console).ToHostType(engine));
This way console.log
is a normal JavaScript function, and the underlying System.Console
host type is inaccessible.
Good luck!
Hi @ClearScriptLib ,
Oh yes, this solves the problem elegantly :) Thanks!
How can we provide a host object to the engine in such a way, that
System.Object
's public members (properties, methods) would not be exposed to the script?For example, if we do
engine.AddHostObject("console", new { log = new Action<string>(Console.WriteLine) });
then theconsole
object and itsconsole.log
property will haveGetHashCode
etc. exposed.I tried using
PropertyBag
likeengine.AddHostObject("console", new PropertyBag { ["log"] = new Action<string>(Console.WriteLine) });
but still, the problem persists withconsole.log
. Perhaps there's somethingPropertyBag
-like for functions?