/// <summary>
        /// Adds new elements to the end of an array, and returns the new length
        /// </summary>
        /// <param name="target">The target list to apply this method on.</param>
        /// <param name="elements">The elements to add</param>
        /// <returns>The new length</returns>
        public int Add(LObject target, params object[] elements)
        {
            if (elements == null || elements.Length == 0)
            {
                return(0);
            }

            // Add
            var list = target.GetValue() as IList;

            if (list == null)
            {
                return(0);
            }

            var table = target as LTable;
            var map   = new LMap(new Dictionary <string, object>());
            var ndx   = 0;

            foreach (var field in table.Fields)
            {
                var val = elements[ndx];
                map.Value[field] = val;
                ndx++;
            }
            list.Add(map);
            return(list.Count);
        }
示例#2
0
 /// <summary>
 /// Evaluate
 /// </summary>
 /// <returns></returns>
 public static object EvalMapType(List<Tuple<string, Expr>> mapExprs)
 {
     // Case 2: Map type
     var dictionary = new Dictionary<string, object>();
     foreach (var pair in mapExprs)
     {
         var expression = pair.Item2;
         object result = expression == null ? null : expression.Evaluate();
         dictionary[pair.Item1] = result;
     }
     var map = new LMap(dictionary);
     return map;
 }
示例#3
0
 // index here
 /// <summary>
 /// Evaluate
 /// </summary>
 /// <returns></returns>
 public object VisitMap(MapExpr expr)
 {
     var mapExprs = expr.Expressions;
     // Case 2: Map type
     var dictionary = new Dictionary<string, object>();
     foreach (var pair in mapExprs)
     {
         var expression = pair.Item2;
         object result = expression == null ? null : expression.Evaluate(this);
         dictionary[pair.Item1] = result;
     }
     var map = new LMap(dictionary);
     return map;
 }