/// <summary>
        /// Get a global variable value from the JavaScript context
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = this._psRt.Runspace.SessionStateProxy.GetVariable(binder.Name);

            if ((result.GetType().IsArray) || (result is Hashtable))
            {
                result = new DynamicInstance(result);
            }

            return(true);
        }
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            result = this._psRt.Runspace.SessionStateProxy.GetVariable(indexes[0].ToString());

            if ((result.GetType().IsArray) || (result is Hashtable))
            {
                result = new DynamicInstance(result);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Returns the value of the key in the dictionary, if the internal data is a dictionary
        /// </summary>
        /// <param name="name"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private object GetValueFromDictionary(string key, object result)
        {
            if (this._dic.ContainsKey(key))
            {
                result = this._dic[key];
                if (result.GetType().IsArray)
                {
                    result = new DynamicInstance(result);
                }

                if (result is PSObject)
                {
                    PSObject p = result as PSObject;
                    result = p.ImmediateBaseObject;
                }
            }
            else
            {
                throw new ParameterBindingException("key:{0} not found in dictionary".format(key));
            }

            return(result);
        }