Beispiel #1
0
        /// <summary>
        /// Returns a string representation of the parsed selector. This may not exactly match the input
        /// selector as it is regenerated.
        /// </summary>
        ///
        /// <returns>
        /// A CSS selector string.
        /// </returns>

        public override string ToString()
        {
            string output = "";

            switch (TraversalType)
            {
            case TraversalType.Child:
                output += " > ";
                break;

            case TraversalType.Descendent:
                output += " ";
                break;

            case TraversalType.Adjacent:
                output += " + ";
                break;

            case TraversalType.Sibling:
                output += " ~ ";
                break;
            }

            if (SelectorType.HasFlag(SelectorType.Elements))
            {
                output += "<ElementList[" + SelectElements.Count() + "]> ";
            }
            if (SelectorType.HasFlag(SelectorType.HTML))
            {
                output += "<HTML[" + Html.Length + "]> ";
            }
            if (SelectorType.HasFlag(SelectorType.Tag))
            {
                output += Tag;
            }
            if (SelectorType.HasFlag(SelectorType.ID))
            {
                output += "#" + ID;
            }

            if (SelectorType.HasFlag(SelectorType.AttributeValue)
                //|| SelectorType.HasFlag(SelectorType.AttributeExists)
                )
            {
                output += "[" + AttributeName;
                if (!String.IsNullOrEmpty(AttributeValue))
                {
                    output += "." + AttributeSelectorType.ToString() + ".'" + AttributeValue + "'";
                }
                output += "]";
            }
            if (SelectorType.HasFlag(SelectorType.Class))
            {
                output += "." + Class;
            }
            if (SelectorType.HasFlag(SelectorType.All))
            {
                output += "*";
            }
            if (SelectorType.HasFlag(SelectorType.PseudoClass))
            {
                output += ":" + PseudoSelector.Name;
                if (PseudoSelector.Arguments != null && PseudoSelector.Arguments.Length > 0)
                {
                    output += "(" + String.Join(",", PseudoSelector.Arguments) + ")";
                }
            }

            return(output);
        }
Beispiel #2
0
        public override string ToString()
        {
            string output = "";

            switch (TraversalType)
            {
            case TraversalType.All:
                output = "";
                break;

            case TraversalType.Child:
                output += " > ";
                break;

            case TraversalType.Descendent:
                output += " ";
                break;
            }
            if (SelectorType.HasFlag(SelectorType.Elements))
            {
                output += "<ElementList[" + SelectElements.Count() + "]> ";
            }
            if (SelectorType.HasFlag(SelectorType.HTML))
            {
                output += "<HTML[" + Html.Length + "]> ";
            }
            if (SelectorType.HasFlag(SelectorType.Tag))
            {
                output += Tag;
            }
            if (SelectorType.HasFlag(SelectorType.ID))
            {
                output += "#" + ID;
            }
            if (SelectorType.HasFlag(SelectorType.Attribute))
            {
                output += "[" + AttributeName;
                if (!String.IsNullOrEmpty(AttributeValue))
                {
                    output += "." + AttributeSelectorType.ToString() + ".'" + AttributeValue + "'";
                }
                output += "]";
            }
            if (SelectorType.HasFlag(SelectorType.Class))
            {
                output += "." + Class;
            }
            if (SelectorType.HasFlag(SelectorType.All))
            {
                output += "*";
            }
            if (SelectorType.HasFlag(SelectorType.Position))
            {
                output += ":" + PositionType.ToString();
                if (IsFunction)
                {
                    output += "(" + PositionIndex + ")";
                }
                else if (SubSelectors.Count > 0)
                {
                    output += SubSelectors.ToString();
                }
            }
            if (SelectorType.HasFlag(SelectorType.Contains))
            {
                output += ":contains(" + Criteria + ")";
            }


            return(output);
        }