Example #1
0
        /// <summary>
        /// Sets the selection set for this object, and asserts that the order in which it as assigned is
        /// the order passed. This allows most operations to return the original set directly; if it is
        /// requested in a different order then it will be sorted.
        /// </summary>
        ///
        /// <param name="selectionSet">
        /// The current selection set including all node types.
        /// </param>
        /// <param name="inputOrder">
        /// The order in which the elements appear in selectionSet. If omitted, Ascending is the default.
        /// </param>
        /// <param name="outputOrder">
        /// The default output order, if different from the inputOrder. If omitted, the same as the input
        /// order is the default.
        /// </param>
        ///
        /// <returns>
        /// The current CQ object.
        /// </returns>

        protected CQ SetSelection(IEnumerable <IDomObject> selectionSet,
                                  SelectionSetOrder inputOrder  = SelectionSetOrder.Ascending,
                                  SelectionSetOrder outputOrder = 0)
        {
            SelectionSet = new SelectionSet <IDomObject>(selectionSet, inputOrder, outputOrder);
            return(this);
        }
 public SelectionSetComparer(SelectionSetOrder order)
 {
     if (order != SelectionSetOrder.Ascending && order != SelectionSetOrder.Descending)
     {
         throw new InvalidOperationException("This comparer can only be used to sort.");
     }
     Order = order;
 }
Example #3
0
        /// <summary>
        /// Returns a new empty CsQuery object bound to this domain, whose results are returned in the specified order
        /// </summary>
        /// <returns></returns>
        public CQ New(SelectionSetOrder order)
        {
            CQ csq = new CQ();

            csq.CsQueryParent = this;
            csq.Order         = order;
            return(csq);
        }
Example #4
0
        /// <summary>
        /// Create an instance based on an existing sequence. The order passed defines the order of the
        /// original list; if the output order should be different than change it.
        ///
        /// The sequence is bound directly as the source of this selection set; it is not enumerated.
        /// Therefore it's possible to create "live" sets that will reflect the same contents as their
        /// original source at any point in time. If a client alters the selection set, however, it
        /// becomes static as the set at that point is copied in order to permit alterations. The
        /// original source sequence is never altered, even if it is a list type that can be altered.
        ///
        /// Because of this care is required. If using an IEnumerable source that is not a basic data
        /// structure, but instead refers to a computationally-intensive process, it might be desirable
        /// to copy it to a list first. The output from the HTML parser and selector engine do this
        /// automatically to prevent accidental misuse. It is conceivable that some future function might
        /// want to provide direct access the the selector engine's IEnumerable output instead of a List
        /// copy to provide a live CSS selector; in this case the engine's Select method would need to be
        /// altered to return the enumerator directly.
        /// </summary>
        ///
        /// <param name="elements">
        /// The sequence to source this selection set.
        /// </param>
        /// <param name="inputOrder">
        /// The list order.
        /// </param>
        /// <param name="outputOrder">
        /// The output order.
        /// </param>

        public SelectionSet(IEnumerable <T> elements, SelectionSetOrder inputOrder, SelectionSetOrder outputOrder)
        {
            OriginalOrder = inputOrder == 0 ?
                            SelectionSetOrder.OrderAdded :
                            inputOrder;
            OutputOrder = outputOrder == 0 ?
                          OriginalOrder :
                          outputOrder;
            OriginalList = elements ?? EmptyList();
        }
Example #5
0
        /// <summary>
        /// Filter a sequence using a selector if the selector is not empty. If it's empty, return a new CQ object
        /// containing the original list.
        /// </summary>
        ///
        /// <param name="selector">
        /// The selector.
        /// </param>
        /// <param name="list">
        /// The source sequence
        /// </param>
        /// <param name="order">
        /// The order in which the elements of the new CQ object should be returned
        /// </param>
        ///
        /// <returns>
        /// A new CQ object
        /// </returns>

        protected CQ FilterIfSelector(string selector, IEnumerable <IDomObject> list, SelectionSetOrder order)
        {
            CQ output;

            if (String.IsNullOrEmpty(selector))
            {
                output = NewInstance(list, this);
            }
            else
            {
                output = NewInstance(FilterElements(list, selector), this);
            }
            output.Order = order;
            return(output);
        }
Example #6
0
        /// <summary>
        /// Sets the selection set for this object to a single element..
        /// </summary>
        ///
        /// <param name="element">
        /// The element to add.
        /// </param>
        /// <param name="outputOrder">
        /// The default output order. If omitted, Ascending (DOM) order is the default.
        /// </param>
        ///
        /// <returns>
        /// The current CQ object
        /// </returns>

        protected CQ SetSelection(IDomObject element,
                                  SelectionSetOrder outputOrder = SelectionSetOrder.Ascending)
        {
            SelectionSet = new SelectionSet <IDomObject>(Objects.Enumerate(element), outputOrder, outputOrder);
            return(this);
        }
Example #7
0
 protected CQ filterIfSelector(string selector,IEnumerable<IDomObject> list, SelectionSetOrder order)
 {
     CQ output;
     if (String.IsNullOrEmpty(selector))
     {
         output= new CQ(list, this);
     }
     else
     {
         output= new CQ(filterElements(list, selector), this);
     }
     output.Order = order;
     return output;
 }
 /// <summary>
 /// Returns a new empty CsQuery object bound to this domain, whose results are returned in the specified order
 /// </summary>
 /// <returns></returns>
 public CQ New(SelectionSetOrder order)
 {
     CQ csq = new CQ();
     csq.CsQueryParent = this;
     csq.Order = order;
     return csq;
 }
Example #9
0
        /// <summary>
        /// Create an initially empty instance whose results are returned in the order specified.
        /// </summary>
        ///
        /// <param name="outputOrder">
        /// The output order.
        /// </param>

        public SelectionSet(SelectionSetOrder outputOrder)
        {
            OriginalOrder = SelectionSetOrder.OrderAdded;
            OutputOrder   = SelectionSetOrder.OrderAdded;
            OriginalList  = EmptyList();
        }