Ejemplo n.º 1
0
 public AttributeSelector2(Selector selector, string attributeName, AttributeSelectorType attributeSelectorType, string value)
 {
     this.Selector              = selector;
     this.AttributeName         = attributeName;
     this.AttributeSelectorType = attributeSelectorType;
     this.Value = value;
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// `this[attributeName type value]` selector.
 /// </summary>
 /// <param name="attributeName">An attribute name.</param>
 /// <param name="type">An attribute selector type.</param>
 /// <param name="value">A value.</param>
 /// <returns>`this[attributeName type value]` selector.</returns>
 public Selector WithAttribute(string attributeName, AttributeSelectorType type, string value)
 {
     return(new AttributeSelector2(this, attributeName, type, value));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// `this[attributeName type value]` selector.
 /// </summary>
 /// <param name="attributeName">An attribute name.</param>
 /// <param name="type">An attribute selector type.</param>
 /// <param name="value">A value.</param>
 /// <returns>`this[attributeName type value]` selector.</returns>
 public Selector this[string attributeName, AttributeSelectorType type, string value] {
     get { return(new AttributeSelector2(this, attributeName, type, value)); }
 }
Ejemplo n.º 5
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);
        }