private static IDictionary <string, object> AppendTreeGridValuesToValuesDictionary(IDictionary <string, object> valuesDictionary, JqGridRecord record)
        {
            JqGridAdjacencyTreeRecord adjacencyTreeRecord = record as JqGridAdjacencyTreeRecord;
            JqGridNestedSetTreeRecord nestedSetTreeRecord = record as JqGridNestedSetTreeRecord;

            if (adjacencyTreeRecord != null)
            {
                valuesDictionary.Add("level", adjacencyTreeRecord.Level);
                valuesDictionary.Add("parent", adjacencyTreeRecord.ParentId);
                valuesDictionary.Add("isLeaf", adjacencyTreeRecord.Leaf);
                valuesDictionary.Add("expanded", adjacencyTreeRecord.Expanded);
            }
            else if (nestedSetTreeRecord != null)
            {
                valuesDictionary.Add("level", nestedSetTreeRecord.Level);
                valuesDictionary.Add("lft", nestedSetTreeRecord.LeftField);
                valuesDictionary.Add("rgt", nestedSetTreeRecord.RightField);
                valuesDictionary.Add("isLeaf", nestedSetTreeRecord.Leaf);
                valuesDictionary.Add("expanded", nestedSetTreeRecord.Expanded);
            }

            return(valuesDictionary);
        }
        private static IDictionary <string, object> SerializeValueRecordAsDictionary(JqGridJsonReader jsonReader, JqGridRecord record, bool isRecordIndexInt, int recordIdIndex, bool isSubgridResponse)
        {
            if (record.Value == null)
            {
                throw new InvalidOperationException("JqGridRecord.Value can't be null when JqGridJsonReader.RepeatItems is set to false.");
            }

            IDictionary <string, object> recordValues = record.GetValueAsDictionary();

            if (!isSubgridResponse && !isRecordIndexInt && !recordValues.ContainsKey(jsonReader.RecordId))
            {
                recordValues.Add(jsonReader.RecordId, record.Id);
            }

            if (!isSubgridResponse)
            {
                recordValues = AppendTreeGridValuesToValuesDictionary(recordValues, record);
            }

            return(recordValues);
        }
        private static IList <object> AppendTreeGridValuesToValuesList(IList <object> valuesList, JqGridRecord record)
        {
            JqGridAdjacencyTreeRecord adjacencyTreeRecord = record as JqGridAdjacencyTreeRecord;
            JqGridNestedSetTreeRecord nestedSetTreeRecord = record as JqGridNestedSetTreeRecord;

            if (adjacencyTreeRecord != null)
            {
                valuesList.Add(adjacencyTreeRecord.Level);
                valuesList.Add(adjacencyTreeRecord.ParentId);
                valuesList.Add(adjacencyTreeRecord.Leaf);
                valuesList.Add(adjacencyTreeRecord.Expanded);
            }
            else if (nestedSetTreeRecord != null)
            {
                valuesList.Add(nestedSetTreeRecord.Level);
                valuesList.Add(nestedSetTreeRecord.LeftField);
                valuesList.Add(nestedSetTreeRecord.RightField);
                valuesList.Add(nestedSetTreeRecord.Leaf);
                valuesList.Add(nestedSetTreeRecord.Expanded);
            }

            return(valuesList);
        }
        private static IList <object> AppendValuesToValuesList(IList <object> valuesList, JqGridRecord record, bool isSubgridResponse)
        {
            foreach (object value in record.Values)
            {
                valuesList.Add(value);
            }

            if (!isSubgridResponse)
            {
                valuesList = AppendTreeGridValuesToValuesList(valuesList, record);
            }

            return(valuesList);
        }
        private static IDictionary <string, object> SerializeValuesRecordAsDictionary(JqGridJsonReader jsonReader, JqGridRecord record, bool isRecordIndexInt, int recordIdIndex, bool isSubgridResponse)
        {
            IDictionary <string, object> recordValues = new Dictionary <string, object>();

            if (!isSubgridResponse)
            {
                recordValues.Add(jsonReader.RecordId, record.Id);
            }

            recordValues.Add(isSubgridResponse ? jsonReader.SubgridReader.RecordValues : jsonReader.RecordValues, AppendValuesToValuesList(new List <object>(), record, isSubgridResponse));

            return(recordValues);
        }
        private static IList <object> SerializeValuesRecordAsList(JqGridJsonReader jsonReader, JqGridRecord record, bool isRecordIndexInt, int recordIdIndex, bool isSubgridResponse)
        {
            IList <object> recordValues = new List <object>();

            if (!isSubgridResponse && Convert.ToString(recordValues[recordIdIndex]) != record.Id)
            {
                recordValues.Add(record.Id);
            }

            return(AppendValuesToValuesList(recordValues, record, isSubgridResponse));
        }