Ejemplo n.º 1
0
        public override object GetProperty(string name)
        {
            VerifyNotDisposed();

            var result = engine.MarshalToHost(engine.ScriptInvoke(() =>
            {
                try
                {
                    return(target.InvokeMember(name, BindingFlags.GetProperty, null, target, MiscHelpers.GetEmptyArray <object>(), null, CultureInfo.InvariantCulture, null));
                }
                catch (Exception)
                {
                    if (target.GetMethod(name, BindingFlags.GetProperty) != null)
                    {
                        // Property retrieval failed, but a method with the given name exists;
                        // create a tear-off method. This currently applies only to VBScript.

                        return(new ScriptMethod(this, name));
                    }

                    return(Nonexistent.Value);
                }
            }), false);

            var resultScriptItem = result as WindowsScriptItem;

            if ((resultScriptItem != null) && (resultScriptItem.engine == engine))
            {
                resultScriptItem.holder = this;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calls a function
        /// </summary>
        /// <param name="functionName">Function name</param>
        /// <param name="args">Function arguments</param>
        /// <returns>Result of the function execution</returns>
        private object InnerCallFunction(string functionName, params object[] args)
        {
            object result;

            try
            {
                result = _dispatch.InvokeMember(functionName, BindingFlags.InvokeMethod,
                                                null, _dispatch, args, null, CultureInfo.InvariantCulture, null);
            }
            catch
            {
                ThrowError();
                throw;
            }

            return(result);
        }