Beispiel #1
0
 public static IEnumerable <T> ElementsAndSelf <T>(this AspxNode item)
 {
     return(item.ElementsAndSelf().Where(i => i is T).Cast <T>());
 }
Beispiel #2
0
 public static IEnumerable <T> Descendants <T>(this AspxNode item)
 {
     return(item.Descendants().Where(i => i is T).Cast <T>());
 }
Beispiel #3
0
 public static IEnumerable <T> AncestorsAndSelf <T>(this AspxNode item)
 {
     return(item.AncestorsAndSelf().Where(i => i is T).Cast <T>());
 }
Beispiel #4
0
        void IParserEventListener.OnTag(Location location, TagType tagType, string name, TagAttributes attributes)
        {
            switch (tagType)
            {
            case TagType.Close:
            {
                string prefix;
                string controlName;
                if (IsAspxTag(name, out prefix, out controlName))
                {
                    // find opening pair tag until the root
                    for (var node = currentNode; !(node is AspxNode.Root); node = node.Parent)
                    {
                        var casted = node as AspxNode.OpenAspxTag;
                        if (casted != null && casted.Prefix == prefix && casted.ControlName == controlName)
                        {
                            currentNode = casted.Parent;
                            break;
                        }
                    }
                }
                else
                {
                    // find closing pair tag no further than first opening ASPX tag
                    for (var node = currentNode; !(node is AspxNode.OpenAspxTag || node is AspxNode.Root); node = node.Parent)
                    {
                        var casted = node as AspxNode.OpenHtmlTag;
                        if (casted != null && casted.Name == name)
                        {
                            currentNode = casted.Parent;
                            break;
                        }
                    }
                }
                currentNode.AddChild(new AspxNode.CloseTag(name, location));
                break;
            }

            case TagType.SelfClosing:
            {
                string prefix;
                string controlName;
                var    newNode = IsAspxTag(name, out prefix, out controlName)
                        ? (AspxNode) new AspxNode.SelfClosingAspxTag(prefix, controlName, attributes, location)
                        : new AspxNode.SelfClosingHtmlTag(name, attributes, location);

                currentNode.AddChild(newNode);
                break;
            }

            case TagType.Open:
            {
                string prefix;
                string controlName;
                var    newNode = IsAspxTag(name, out prefix, out controlName)
                        ? (AspxNode) new AspxNode.OpenAspxTag(prefix, controlName, attributes, location)
                        : new AspxNode.OpenHtmlTag(name, attributes, location);

                currentNode.AddChild(newNode);
                currentNode = newNode;
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(tagType), tagType, null);
            }
        }