Пример #1
0
 protected virtual Expression GetColumnsExpression(DataTable table, JsonPath currentPath, IExpressionBuilder serializer)
 {
     ArrayExpression columns = new ArrayExpression();
     int colCount = 0;
     foreach (DataColumn dc in table.Columns)
     {
         columns.Add(GetColumnExpression(dc, currentPath.Append(colCount), serializer));
         colCount++;
     }
     return columns;
 }
Пример #2
0
        /// <summary>
        /// Serializes the data into a json array expression.
        /// </summary>
        /// <param name="data">the data to serialize</param>
        /// <param name="currentPath">the current path to the data</param>
        /// <param name="serializer">serializer instance to use to serialize list items</param>
        /// <returns>a json array expression representation</returns>
        public override Expression GetExpression(object data, JsonPath currentPath, IExpressionBuilder serializer)
        {
            TypeData handler = Config.GetTypeHandler(data.GetType());

            CollectionHandler collectionHandler = handler.CollectionHandler;
            Type elemType = collectionHandler.GetItemType(handler.ForType);

            int index = 0;

            ArrayExpression expression = new ArrayExpression();
            foreach (object value in collectionHandler.GetEnumerable(data))
            {
                Expression itemExpr = serializer.Serialize(value, currentPath.Append(index));
                if (value != null && !ReflectionUtils.AreEquivalentTypes(value.GetType(), elemType))
                {
                    itemExpr = new CastExpression(value.GetType(), itemExpr);
                }
                expression.Add(itemExpr);
                index++;
            }
            return expression;
        }
Пример #3
0
 protected virtual Expression GetRowsExpression(DataTable table, JsonPath currentPath, IExpressionBuilder serializer)
 {
     ArrayExpression rowsExpr = new ArrayExpression();
     for (int i = 0; i < table.Rows.Count; i++)
     {
         DataRow row = table.Rows[i];
         object[] values = row.ItemArray;
         JsonPath rowPath = currentPath.Append(i);
         ArrayExpression rowExpr = new ArrayExpression();
         for (int j = 0; j < values.Length; j++)
         {
             rowExpr.Add(serializer.Serialize(values[j], rowPath.Append(j)));
         }
         rowsExpr.Add(rowExpr);
     }
     return rowsExpr;
 }
Пример #4
0
 /// <summary>
 /// Parses a javascript array
 /// </summary>
 /// <returns></returns>
 private ArrayExpression ParseCollection()
 {
     Token tok = ReadToken();
     Debug.Assert(tok == LSquareToken);
     ArrayExpression value = new ArrayExpression() { LineNumber = tok.linenumber, CharacterPosition = tok.position };
     Expression item;
     bool first = true;
     while (ReadAhead(CommaToken, RSquareToken, new ExpressionMethod(ParseExpression), out item, ref first))
     {
         value.Add(item);
     }
     return value;
 }