private void del(IJSONObject node) { node.clear(); var childs = node.__getChildsNames(); foreach (var c in childs) { del(node.__getChild(c)); } childs.Clear(); /* * var parentNodesNames = node.parent.__getChildsNames(); * for (int cont = 0; cont < parentNodesNames.Count; cont++) * { * if (parentNodesNames[cont] == node) * { * //if parent is an array, pull the elements forward backwards * if (node.parent.isArray()) * { * for (int cont2 = cont; cont2 < parentNodes.Count - 1; cont2++) * parentNodes[parentNodes.ElementAt(cont2).Key] = parentNodes[parentNodes.ElementAt(cont2 + 1).Key]; * * parentNodes.Remove(parentNodes.Last().Key); * } * else * { * parentNodes.Remove(parentNodes.ElementAt(cont).Key); * } * break; * } * }*/ }
private IJSONObject find(string objectName, bool autoCreateTree, IJSONObject currentParent, SOType forceType = SOType.Undefined) { //quebra o nome em um array objectName = objectName.Replace("]", "").Replace("[", "."); string currentName = objectName; string childsNames = ""; IJSONObject childOnParent; if (objectName.IndexOf('.') > -1) { currentName = objectName.Substring(0, objectName.IndexOf('.')); childsNames = objectName.Substring(objectName.IndexOf('.') + 1); } if (!(currentParent.__containsChild(currentName))) { if (autoCreateTree) { IJSONObject tempObj; string currentParentRelativeName = currentParent.getRelativeName(); if (currentParent is InMemoryJsonObject) { tempObj = new InMemoryJsonObject((InMemoryJsonObject)currentParent, currentParent.getRelativeName() + (currentParentRelativeName.Contains('.') ? "." : "") + currentName); } else { tempObj = new FileSystemJsonObject((FileSystemJsonObject)currentParent, currentParent.getRelativeName() + (currentParentRelativeName.Contains('.') ? "." : "") + currentName, (string)JsonObjectArguments); } if (forceType != SOType.Undefined) { tempObj.forceType(forceType); } currentParent.setChild(currentName, tempObj); } else { return(null); } } childOnParent = currentParent.__getChild(currentName); if (childsNames == "") { return(childOnParent); } else { return(this.find(childsNames, autoCreateTree, childOnParent)); } }
public void clearChilds(string objectName) { IJSONObject temp = this.find(objectName, false, this.root); if (temp != null) { //var childs = temp.__getChilds(); var names = temp.__getChildsNames(); foreach (var c in names) { del(temp.__getChild(c)); } } }
private List <string> getObjectsNames(IJSONObject currentItem = null) { List <string> retorno = new List <string>(); if (currentItem == null) { currentItem = this.root; } string parentName = ""; List <string> childsNames; var chieldsNames = currentItem.__getChildsNames(); for (int cont = 0; cont < chieldsNames.Count; cont++) { childsNames = getObjectsNames(currentItem.__getChild(chieldsNames[cont])); parentName = chieldsNames[cont]; //adiciona os filhos ao resultado //verifica se o nome atual atende ao filtro foreach (var att in childsNames) { string nAtt = att; if (nAtt != "") { nAtt = parentName + '.' + nAtt; } retorno.Add(nAtt); } retorno.Add(chieldsNames[cont]); } return(retorno); }