//todo - check if can be subsumed into submit to stack - to avoid casting
        public void JsonEndArray(int pos)
        {
            ArrayFrame holder = (ArrayFrame)objects.Pop();

            object[] value = new object[holder.objectList.Count];
            for (int done = 0; done < holder.objectList.Count; done++)
            {
                value[done] = holder.objectList[done];
            }
            StackFrame context = objects.Peek();

            if (context is FunctionHolder)
            {
                ((FunctionHolder)context).paramList.Add(value);
            }
            else if (context is ObjectFrame)
            {
                string strError = setValueinObject(((ObjectFrame)context).theObject, holder.propertyName, value, listener);
                if (strError != null)
                {
                    throw new Exception("failed to set value because " + strError);
                }
            }
            else
            {
                throw new Exception("unexpected StackFrame: " + context.GetType().FullName + " for JsonEndArray pos=" + pos);
            }
        }
        public void JsonStartArray(string propertyName, int pos)
        {
            ArrayFrame holder = new ArrayFrame();

            holder.objectList   = new List <Object>();
            holder.propertyName = propertyName;
            objects.Push(holder);
        }
        Type inferCurrentTypeFromStack(bool autocreate)
        {
            if (this.objects.Count == 0)
            {
                return(null);
            }
            Type currentType = null;
            Type parentType  = null;

            for (int done = (this.objects.Count - 1); done >= 0; done--)
            {
                parentType  = currentType;
                currentType = null;
                ObjectFrame oFrame       = this.objects.ElementAt(done) as ObjectFrame;
                ArrayFrame  aFrame       = this.objects.ElementAt(done) as ArrayFrame;
                string      propertyName = null;
                if (oFrame != null)
                {
                    currentType = oFrame.theObject != null?oFrame.theObject.GetType() : null;

                    propertyName = oFrame.propertyName;
                }
                if (aFrame != null)
                {
                    propertyName = aFrame.propertyName;
                }

                if (currentType == null && parentType != null)
                {
                    //infer from the parentType and propertyName
                    if (propertyName != null)
                    {
                        PropertyInfo pi = parentType.GetProperty(propertyName);
                        if (pi != null)
                        {
                            currentType = pi.PropertyType;
                        }
                    }
                    else if (parentType.IsGenericType)
                    {
                        Type[] gtypes = parentType.GetGenericArguments();
                        if (gtypes != null && gtypes.Length == 1)
                        {
                            currentType = gtypes[0];
                        }
                    }
                }
                if (autocreate && currentType != null && oFrame != null && oFrame.theObject == null)
                {
                    oFrame.theObject = newInstance(currentType);
                }
            }
            return(currentType);
        }
 public void JsonStartArray(string propertyName, int pos)
 {
     ArrayFrame holder = new ArrayFrame();
     holder.objectList = new List<Object>();
     holder.propertyName = propertyName;
     objects.Push(holder);
 }