示例#1
0
        public TemplateLink AddListLink(string name, string link)
        {
            TemplateLink result = this.AddLink(name, new TemplateLink(this, link));

            result.IsList = true;
            return(result);
        }
示例#2
0
 public TemplateLink AddLink(string name, TemplateLink link)
 {
     this.AddAttribute(name, link);
     return link;
 }
示例#3
0
        /// <summary>
        /// Gets an object by path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public object GetByPath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(this);
            }
            if (path.StartsWith("/"))
            {
                return(this.Root.GetByPath(path.Substring(1)));
            }
            if (path.StartsWith("../"))
            {
                if (this.Parent == null)
                {
                    return(null);
                }
                return(this.Parent.GetByPath(path.Substring(3)));
            }
            string currentPath = this.Pop(ref path);
            object result      = null;

            if (currentPath.StartsWith("["))
            {
                if (!this.IsList)
                {
                    return(null);
                }
                string arrayPos = currentPath.Substring(1, currentPath.Length - 2);
                if (arrayPos.StartsWith("*"))
                {
                    arrayPos = arrayPos.Substring(1);
                    int iarrayPos;
                    if (!int.TryParse(arrayPos, out iarrayPos))
                    {
                        return(null);
                    }
                    if ((iarrayPos < 0) || (iarrayPos >= this.ArrayValues.Count))
                    {
                        return(null);
                    }
                    result = this.ArrayValues[iarrayPos];
                }
                else
                {
                    if (this.ArrayValuesMap.ContainsKey(arrayPos))
                    {
                        result = this.ArrayValuesMap[arrayPos];
                    }
                }
            }
            else
            {
                if (!this.Attributes.ContainsKey(currentPath))
                {
                    return(null);
                }
                result = this.Attributes[currentPath];
            }
            while (result is TemplateLink)
            {
                if (string.IsNullOrEmpty(path))
                {
                    return(result);
                }
                TemplateLink link = (result as TemplateLink);
                if (link.IsList)
                {
                    if (path.StartsWith("["))
                    {
                        currentPath = this.Pop(ref path);
                        string arrayPos     = currentPath.Substring(1, currentPath.Length - 2);
                        string convertedPos = link.ListValues[int.Parse(arrayPos)];
                        object obj          = this.GetByPath(link.Link);
                        if (obj is TemplateContainer)
                        {
                            if ((obj as TemplateContainer).IsList)
                            {
                                result = (obj as TemplateContainer).ArrayValuesMap[convertedPos];
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                    else
                    {
                        result = null;
                    }
                }
                else
                {
                    result = this.GetByPath((result as TemplateLink).Link);
                }
            }
            if (string.IsNullOrEmpty(path))
            {
                return(result);
            }
            if (result is TemplateContainer)
            {
                return((result as TemplateContainer).GetByPath(path));
            }
            else
            {
                return(null);
            }
        }
示例#4
0
 public TemplateLink AddLink(string name, TemplateLink link)
 {
     this.AddAttribute(name, link);
     return(link);
 }