public Compiler() { engine = new ScriptEngine("jscript"); var underscore = LoadResource("underscore.js") + LoadResource("underscore.compile.js"); vm = engine.Parse(underscore); }
/// <summary> /// Evaluates an expression using the specified language, with an optional array of named items. /// </summary> /// <param name="language">The language.</param> /// <param name="expression">The expression. May not be null.</param> /// <param name="namedItems">The named items array.</param> /// <returns>The result of the evaluation.</returns> public static object Eval(string language, string expression, params KeyValuePair<string, object>[] namedItems) { if (language == null) throw new ArgumentNullException("language"); if (expression == null) throw new ArgumentNullException("expression"); using (var engine = new ScriptEngine(language)) { if (namedItems != null) { foreach (KeyValuePair<string, object> kvp in namedItems) { engine.SetNamedItem(kvp.Key, kvp.Value); } } return engine.Eval(expression); } }
internal ParsedScript(ScriptEngine engine, IntPtr dispatch) { this.engine = engine; this.dispatch = Marshal.GetObjectForIUnknown(dispatch); }