public KeyValuePair <string, object> GetKeyValuePair(KeyValueNode node) { object value = null; if (node.Value is ListKeyValueNode) { // has key, value var listKeyvalueNodeParser = new ListKeyValueNodeParser(); Dictionary <string, object> dictionary = listKeyvalueNodeParser.GetDictionary(node.Value as ListKeyValueNode); value = dictionary; } //else if (node.Value is KeyArrayNode) //{ // var keyArrayNodeParser = new KeyArrayNodeParser(); // KeyValuePair<string, ArrayList> keyValueArrayPair = keyArrayNodeParser.GetKeyArrayListPair(node.Value as KeyArrayNode); // value = keyValueArrayPair; //} else if (node.Value is ValueNode) { var ValueNodeParser = new ValueNodeParser(); var valueNode = ValueNodeParser.GetDictionaryValue(node.Value as ValueNode); value = valueNode; } var keyArrayListPair = new KeyValuePair <string, object>(node.Key, value); return(keyArrayListPair); }
public ArrayList GetArrayList(ArrayNode arrayNode) { ArrayList arrayList = new ArrayList(); foreach (var item in arrayNode.Values) { if (item is ListKeyValueNode) { // has key, value var listKeyvalueNodeParser = new ListKeyValueNodeParser(); var listKeyvalueNode = listKeyvalueNodeParser.GetDictionary(item as ListKeyValueNode); arrayList.Add(listKeyvalueNode); } else if (item is ArrayNode) { var arrayNodeParser = new ArrayNodeParser(); var innerArrayList = arrayNodeParser.GetArrayList(item as ArrayNode); arrayList.Add(innerArrayList); } else if (item is ValueNode) { var ValueNodeParser = new ValueNodeParser(); var value = ValueNodeParser.GetDictionaryValue(item as ValueNode); arrayList.Add(value); } else { throw new Exception(); } } return(arrayList); }
public INode GetKeyValueNode(KeyValuePair <string, object> keyValuePair) { INode value = null; if (keyValuePair.Value is Dictionary <string, object> ) { // has key, value var listKeyvalueNodeParser = new ListKeyValueNodeParser(); var listKeyvalueNode = listKeyvalueNodeParser.GetKeyValueNodes(keyValuePair.Value as Dictionary <string, object>, 0); value = listKeyvalueNode; } //else if (keyValuePair.Value is ArrayList) //{ // var keyArrayNodeParser = new KeyArrayNodeParser(); // var arrayNode = keyArrayNodeParser.GetArrayListNode(keyValuePair.Key, keyValuePair.Value as ArrayList); // value = arrayNode; //} else if (keyValuePair.Value is object) // needs to be last { var ValueNodeParser = new ValueNodeParser(); var valueNode = ValueNodeParser.GetValueNode(keyValuePair.Value as object); value = valueNode; } KeyValueNode rootnode = new KeyValueNode(); rootnode.Key = keyValuePair.Key; rootnode.Value = value; return(rootnode); }
public ArrayNode GetArrayNode(ArrayList arrayList) { List <INode> nodes = new List <INode>(); int counter = 0; foreach (var item in arrayList) { if (item is Dictionary <string, object> ) { // has key, value var listKeyvalueNodeParser = new ListKeyValueNodeParser(); var listKeyvalueNode = listKeyvalueNodeParser.GetKeyValueNodes(item as Dictionary <string, object>, counter); nodes.Add(listKeyvalueNode); } else if (item is ArrayList) { // array that does not have a key var arrayNodeParser = new ArrayNodeParser(); var arrayNode = arrayNodeParser.GetArrayNode(item as ArrayList); nodes.Add(arrayNode); } else if (item is object) { var ValueNodeParser = new ValueNodeParser(); var valueNode = ValueNodeParser.GetValueNode(item as object); nodes.Add(valueNode); } else { throw new Exception(); } counter++; } var ArrayNode = new ArrayNode() { Values = nodes, }; return(ArrayNode); }