protected override void OnBeginTypedArray(MarkerCode typeOfElement, int elemCount) { PushCurrentState(); //enter new state : create new array, and set to current object _currentObject = _currentArray = _doc.CreateArray(); //expect array value _state = ParsingState.ExpectArrayValue; }
protected override void OnBeginArray() { PushCurrentState(); //enter new state : create new array, and set to current object _currentObject = _currentArray = _doc.CreateArray(); //expect array value _state = ParsingState.ExpectArrayValue; }
/// <summary> /// convert json to lq element /// </summary> /// <param name="element"></param> static void ReFormatLqElement(LiquidElement element) { LiquidAttribute childNodeAttr = null; LiquidAttribute nodeNameAttr = null; if (!element.HasOwnerDocument) { return; } LiquidDoc ownerdoc = element.OwnerDocument; int found_N = element.OwnerDocument.GetStringIndex("!n"); int found_C = element.OwnerDocument.GetStringIndex("!c"); foreach (LiquidAttribute att in element.GetAttributeIterForward()) { if (found_N != 0 && att.AttributeLocalNameIndex == found_N) //!n { element.Name = att.Value.ToString(); nodeNameAttr = att; } else if (found_C != 0 && att.AttributeLocalNameIndex == found_C) { childNodeAttr = att; } } //-------------------------------------- if (nodeNameAttr != null) { element.RemoveAttribute(nodeNameAttr); } //-------------------------------------- if (childNodeAttr != null) { if (childNodeAttr.Value is LiquidArray) { LiquidArray children = (LiquidArray)childNodeAttr.Value; foreach (object child in children.GetIterForward()) { if (child is LiquidElement) { ReFormatLqElement((LiquidElement)child); element.AppendChild((LiquidElement)child); } else { throw new NotSupportedException(); } } children.Clear(); element.RemoveAttribute(childNodeAttr); } } }
public void WriteArray(LiquidArray arr) { WriteStartArray(); int count = arr.Count; for (int i = 0; i < count; ++i) { WriteObject(arr[i]); } WriteEndArray(); }
protected override void OnEndArray() { //end current array LiquidArray tmpCurrentObject = _currentArray; string prevKey = _keyName; RestorePrevState(); switch (_state) { case ParsingState.ExpectArrayValue: _currentArray = (LiquidArray)_currentObject; _currentArray.AddItem(_currentArray); break; case ParsingState.ExpectKeyValue: _currentElement = (LiquidElement)_currentObject; AppendKeyValue(_currentArray); break; default: throw new NotSupportedException(); } }
static void AddVElement(LiquidArray dArray, object velemt) { dArray.AddItem(velemt); }