This project has moved. For the latest updates, please go here.

global object - types

Nov 14, 2015 at 5:27 PM
hello,

i know you can add a global object like in browser - window

so is it possible to add types to this object?

so something like -

globals.XmlHttpRequest
Coordinator
Nov 16, 2015 at 4:26 AM
Edited Nov 16, 2015 at 4:30 AM
Hi furesoft,

You can use ClearScript's ExtendedHostFunctions for this purpose. Here's a sample:
public class XmlHttpRequest {
    public static void SomeMethod() {
        // code goes here
    }
}
public class Globals {
    private readonly ExtendedHostFunctions _extHost = new ExtendedHostFunctions();
    public object XmlHttpRequest {
        get { return _extHost.type(typeof(XmlHttpRequest)); }
    }
}
And then:
engine.Script.globals = new Globals();
engine.Execute("globals.XmlHttpRequest.SomeMethod()");
Good luck!