Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Elevated library layer

0
0
Hello Querty,

Suppose you have a class that provides sensitive host functionality:
publicclass HostLib {
    publicvoid Log(string message) {
        Console.WriteLine(message);
    }
}
Here's how you might create a script library that uses that class without exposing it to other script code:
dynamic createScriptLib = engine.Evaluate(@"
    (function (hostLib) {
        return {
            log: function (message) {
                hostLib.Log(message);
            }
        };
    }).valueOf()
");

engine.Script.lib = createScriptLib(new HostLib());
With this setup, additional script code (such as the plugin code) can invoke the "elevated" library (e.g., lib.log('Hello, world!')), but it has no access to the host object that provides the underlying functionality.

Good luck!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images