コード例 #1
0
        /// <summary>
        /// Added by chuan.yin in 2017/4/27
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private object[] ToArray(JsValue value)
        {
            var length = value.ArrayLength;

            List <object> rtn = new List <object>();

            for (var i = 0; i < length; i++)
            {
                var jsv = value.GetIndexedProperty(JsValue.FromInt32(i));
                rtn.Add(MapToHostType(jsv));
            }
            return(rtn.ToArray());
        }
コード例 #2
0
        public static IEnumerable <JsValue> EnumerateArrayValues(this JsValue val)
        {
            if (val.ValueType != JsValueType.Array)
            {
                throw new InvalidOperationException("Can't enumerate non array value");
            }
            var lenId = JsPropertyId.FromString("length");
            var len   = val.GetProperty(lenId).ToInt32();

            for (var i = 0; i < len; i++)
            {
                yield return(val.GetIndexedProperty(JsValue.FromInt(i)));
            }
        }
コード例 #3
0
        private JToken VisitArray(JsValue value)
        {
            var array      = new JArray();
            var propertyId = JsPropertyId.FromString("length");
            var length     = value.GetProperty(propertyId).ToInt32();

            for (var i = 0; i < length; ++i)
            {
                var index   = JsValue.FromInt(i);
                var element = value.GetIndexedProperty(index);
                array.Add(Visit(element));
            }

            return(array);
        }