Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        public FileSystemJsonObject(FileSystemJsonObject parent, string relativeName, string arguments)
        {
            /*if (parent != null)
             *  this.baseFolder = parent.__getBaseFolder();
             * else*/
            this.baseFolder = arguments;
            this.baseFolder = this.baseFolder.Replace("\\", "/");

            if (this.baseFolder[this.baseFolder.Length - 1] == '/')
            {
                this.baseFolder = this.baseFolder.Substring(0, this.baseFolder.Length - 1);
            }

            this.fileName = this.baseFolder + relativeName.Replace(".", "/");

            if (fileName != "" && fileName[fileName.Length - 1] == '/')
            {
                fileName = fileName.Substring(0, fileName.Length - 1);
            }

            this.relativeName = relativeName;
        }