コード例 #1
0
        /// <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 (JSEngine engine = new JSEngine(language))
            {
                if (namedItems != null)
                {
                    foreach (KeyValuePair <string, object> kvp in namedItems)
                    {
                        engine.SetNamedItem(kvp.Key, kvp.Value);
                    }
                }
                return(engine.Eval(expression));
            }
        }
コード例 #2
0
 internal ParsedScript(JSEngine engine, IntPtr dispatch)
 {
     _engine   = engine;
     _dispatch = Marshal.GetObjectForIUnknown(dispatch);
 }