Пример #1
0
        private XjsltJson ReadArray(JArray n)
        {
            var arr = new XjsltArray(n.Count);

            foreach (var item in n)
            {
                var it = arr.Item = Read(item);
                if (it.Source != null)
                {
                    arr.Source = it.Source;
                    it.Source  = null;
                }
                else
                {
                    throw new MissingFieldException("$source");
                }
            }

            return(arr);
        }
Пример #2
0
        public object VisitArray(XjsltArray node)
        {
            using (var ctx = NewContext())
            {
                var src = ctx.Current.Source;

                var target = src.AddVar(typeof(JArray), null, typeof(JArray).CreateObject());
                ctx.Current.RootTarget = target;

                var resultToken = src.AddVar((typeof(JToken)), null, (Expression)node.Source.Accept(this));

                // Case when result is array
                var i         = src.If(resultToken.TypeIs(typeof(JArray)));
                var listArray = i.Then.AddVar(typeof(JArray), null, resultToken.ConvertIfDifferent(typeof(JArray)));

                var if1 = i.Then.For(Expression.Constant(0), listArray.Property("Count"));
                if1.Where          = Expression.LessThan(if1.Index, listArray.Property("Count"));
                ctx.Current.Source = if1.Body;

                var itemList = if1.Body.AddVar((typeof(JToken)), null, Expression.Property(listArray, _propJArray_Item, if1.Index));
                ctx.Current.RootSource = itemList;

                var b = (Expression)node.Item.Accept(this);
                if1.Body.Add(target.Call(this._AddJArray, b));


                // Case when else
                ctx.Current.Source     = i.Else;
                ctx.Current.RootSource = resultToken;
                b = (Expression)node.Item.Accept(this);
                i.Else.Add(target.Call(this._AddJArray, b));


                return(target);
            }
        }
Пример #3
0
 public object VisitArray(XjsltArray node)
 {
     throw new NotImplementedException();
 }