public Compiler() { _engine = new ScriptEngine("jscript"); Debug.Assert(!string.IsNullOrWhiteSpace(LoadResource("compiler.js"))); _vm = _engine.Parse(LoadResource("compiler.js")); }
/// <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 (ScriptEngine 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) { _engine = engine; _dispatch = Marshal.GetObjectForIUnknown(dispatch); }