public override bool TryGetValue(IJSONDocument document, out AttributeValue[] value) { value = null; string currentAttribute = _attribute.Name; if (document.Contains(currentAttribute)) { ExtendedJSONDataTypes type = document.GetAttributeDataType(currentAttribute); switch (type) { case ExtendedJSONDataTypes.Array: Array objectsArray = document.GetArray <object>(currentAttribute); return(TryGetArray(objectsArray, out value)); default: IComparable dataValue; if (document.TryGet(currentAttribute, out dataValue)) { if (dataValue != null) { value = new AttributeValue[] { new SingleAttributeValue(dataValue) }; } else { value = new[] { NullValue.Null }; } return(true); } return(false); } } return(false); }
/// <summary> /// Gets the type of value at specified column index. /// </summary> /// <param name="index">Index of the column (0 based index)</param> /// <returns>Type of value at the specified index.</returns> public override Type GetFieldType(int index) { if (index >= 0 && _attributeCols.Count > index && _dbReader != null) { ExtendedJSONDataTypes type = _dbReader.GetAttributeDataType(_attributeCols[index].ToString()); switch (type) { case ExtendedJSONDataTypes.Boolean: return(typeof(bool)); case ExtendedJSONDataTypes.DateTime: return(typeof(DateTime)); case ExtendedJSONDataTypes.Number: return(typeof(double)); case ExtendedJSONDataTypes.Null: return(typeof(string)); // nullable string... case ExtendedJSONDataTypes.Array: return(typeof(Array)); case ExtendedJSONDataTypes.Object: return(typeof(object)); case ExtendedJSONDataTypes.String: return(typeof(string)); } } throw new Exception("Index is not valid. Use [name] if * is used in the Query."); }
private static void ExpandAttribute(IJSONDocument source, Queue <string> attributeQueue, object newValue) { string currentAttribute = attributeQueue.Dequeue(); bool lastAttribute = attributeQueue.Count == 0; if (lastAttribute) { source[currentAttribute] = newValue; } else { if (source.Contains(currentAttribute)) { ExtendedJSONDataTypes type = source.GetAttributeDataType(currentAttribute); switch (type) { case ExtendedJSONDataTypes.Object: //Recurecurecurecurecurecurecurecurecurecurecurecurecurecurecursion ExpandAttribute(source.GetDocument(currentAttribute), attributeQueue, newValue); break; default: IJSONDocument subDocument = JSONType.CreateNew(); source[currentAttribute] = subDocument; ExpandAttribute(subDocument, attributeQueue, newValue); break; } } else { IJSONDocument subDocument = JSONType.CreateNew(); source[currentAttribute] = subDocument; ExpandAttribute(subDocument, attributeQueue, newValue); } } }
public void UpdateAttribute(IJSONDocument document, IJsonValue newValue) { if (document.Contains(_name)) { if (_indecies != null && _indecies.Length > 0) { ExtendedJSONDataTypes type = document.GetAttributeDataType(_name); if (type == ExtendedJSONDataTypes.Array) { List <IJsonValue> ijsonList = JsonDocumentUtil.ToIJsonList((IEnumerable)document[_name]); if (_indecies != null && _indecies.Length > 0) { if (_childAttribute != null && ijsonList.Count > _indecies[0]) { if (ijsonList[_indecies[0]].Value is IJSONDocument) { _childAttribute.UpdateAttribute(ijsonList[_indecies[0]].Value as IJSONDocument, newValue); } } else { // Update value in list and replace list in the document. ijsonList[_indecies[0]] = newValue; var values = new ArrayList(ijsonList.Count); foreach (var jsonValue in ijsonList) { values.Add(jsonValue.Value); } document[_name] = values.ToArray(); } } else { foreach (IJsonValue jsondoc in ijsonList) { ((JSONDocument)jsondoc.Value)[_name] = newValue.Value; } } } } else { if (_childAttribute != null) { if (document[_name] is IJSONDocument) { _childAttribute.UpdateAttribute(document[_name] as IJSONDocument, newValue); } else { ExtendedJSONDataTypes type = document.GetAttributeDataType(_name); if (type == ExtendedJSONDataTypes.Array) { List <IJsonValue> ijsonList = JsonDocumentUtil.ToIJsonList((IEnumerable)document[_name]); foreach (IJsonValue jsondoc in ijsonList) { _childAttribute.UpdateAttribute((JSONDocument)jsondoc.Value, newValue); } } } } else { document[_name] = newValue.Value; } } } else { document[_name] = newValue.Value; } }