Esempio n. 1
0
            /// <summary>
            /// Moves the enumerator to the next item.
            /// </summary>
            /// <returns>True if there is a next item, false otherwise.</returns>
            public bool MoveNext()
            {
                if (this.collectionStack == null)
                {
                    if (this.collection.Count == 0)
                    {
                        return(false);
                    }

                    this.collectionStack = new Stack();
                    this.collectionStack.Push(new CollectionTuple(this.collection));
                }

                CollectionTuple tuple = (CollectionTuple)this.collectionStack.Peek();

                if (this.FindNext(tuple))
                {
                    return(true);
                }

                this.collectionStack.Pop();
                if (this.collectionStack.Count == 0)
                {
                    return(false);
                }

                return(this.MoveNext());
            }
Esempio n. 2
0
            private bool FindNext(CollectionTuple tuple)
            {
                object container = tuple.Collection.items[tuple.ContainerIndex];

                CollectionItem collectionItem = container as CollectionItem;

                if (collectionItem != null)
                {
                    if (tuple.ItemIndex + 1 < collectionItem.Elements.Count)
                    {
                        tuple.ItemIndex++;
                        return(true);
                    }
                }

                ElementCollection elementCollection = container as ElementCollection;

                if (elementCollection != null && elementCollection.Count > 0 && tuple.ItemIndex == -1)
                {
                    tuple.ItemIndex++;
                    this.PushCollection(elementCollection);
                    return(true);
                }

                tuple.ItemIndex = 0;

                for (int i = tuple.ContainerIndex + 1; i < tuple.Collection.items.Count; ++i)
                {
                    object nestedContainer = tuple.Collection.items[i];

                    CollectionItem nestedCollectionItem = nestedContainer as CollectionItem;
                    if (nestedCollectionItem != null)
                    {
                        if (nestedCollectionItem.Elements.Count > 0)
                        {
                            tuple.ContainerIndex = i;
                            return(true);
                        }
                    }

                    ElementCollection nestedElementCollection = nestedContainer as ElementCollection;
                    if (nestedElementCollection != null && nestedElementCollection.Count > 0)
                    {
                        tuple.ContainerIndex = i;
                        this.PushCollection(nestedElementCollection);
                        return(true);
                    }
                }

                return(false);
            }
Esempio n. 3
0
            private void PushCollection(ElementCollection collection)
            {
                if (collection.Count <= 0)
                {
                    throw new ArgumentException(String.Format(
                                                    CultureInfo.InvariantCulture,
                                                    "Collection has {0} elements. Must have at least one.",
                                                    collection.Count));
                }

                CollectionTuple tuple = new CollectionTuple(collection);

                this.collectionStack.Push(tuple);
                this.FindNext(tuple);
            }
Esempio n. 4
0
            /// <summary>
            /// Pushes a collection onto the stack.
            /// </summary>
            /// <param name="elementCollection">The collection to push.</param>
            private void PushCollection(ElementCollection elementCollection)
            {
                if (elementCollection.Count <= 0)
                {
                    throw new ArgumentException(String.Format(
                                                    CultureInfo.InvariantCulture,
                                                    WixStrings.EXP_CollectionMustHaveAtLeastOneElement,
                                                    elementCollection.Count));
                }

                CollectionTuple tuple = new CollectionTuple(elementCollection);

                this.collectionStack.Push(tuple);
                this.FindNext(tuple);
            }
Esempio n. 5
0
            /// <summary>
            /// Pushes a collection onto the stack.
            /// </summary>
            /// <param name="elementCollection">The collection to push.</param>
            private void PushCollection(ElementCollection elementCollection)
            {
                if (elementCollection.Count <= 0)
                {
                    throw new ArgumentException(String.Format(
                        CultureInfo.InvariantCulture,
                        WixStrings.EXP_CollectionMustHaveAtLeastOneElement,
                        elementCollection.Count));
                }

                CollectionTuple tuple = new CollectionTuple(elementCollection);
                this.collectionStack.Push(tuple);
                this.FindNext(tuple);
            }
Esempio n. 6
0
            /// <summary>
            /// Finds the next item from a given tuple.
            /// </summary>
            /// <param name="tuple">The tuple to start looking from.</param>
            /// <returns>True if a next element is found, false otherwise.</returns>
            private bool FindNext(CollectionTuple tuple)
            {
                object container = tuple.Collection.items[tuple.ContainerIndex];

                CollectionItem collectionItem = container as CollectionItem;
                if (collectionItem != null)
                {
                    if (tuple.ItemIndex + 1 < collectionItem.Elements.Count)
                    {
                        tuple.ItemIndex++;
                        return true;
                    }
                }

                ElementCollection elementCollection = container as ElementCollection;
                if (elementCollection != null && elementCollection.Count > 0 && tuple.ItemIndex == -1)
                {
                    tuple.ItemIndex++;
                    this.PushCollection(elementCollection);
                    return true;
                }

                tuple.ItemIndex = 0;

                for (int i = tuple.ContainerIndex + 1; i < tuple.Collection.items.Count; ++i)
                {
                    object nestedContainer = tuple.Collection.items[i];

                    CollectionItem nestedCollectionItem = nestedContainer as CollectionItem;
                    if (nestedCollectionItem != null)
                    {
                        if (nestedCollectionItem.Elements.Count > 0)
                        {
                            tuple.ContainerIndex = i;
                            return true;
                        }
                    }

                    ElementCollection nestedElementCollection = nestedContainer as ElementCollection;
                    if (nestedElementCollection != null && nestedElementCollection.Count > 0)
                    {
                        tuple.ContainerIndex = i;
                        this.PushCollection(nestedElementCollection);
                        return true;
                    }
                }

                return false;
            }
            /// <summary>
            /// Pushes a collection onto the stack.
            /// </summary>
            /// <param name="collection">The collection to push.</param>
            private void PushCollection(ElementCollection collection)
            {
                if (collection.Count <= 0)
                {
                    throw new ArgumentException(String.Format(
                        CultureInfo.InvariantCulture,
                        "Collection has {0} elements. Must have at least one.",
                        collection.Count));
                }

                CollectionTuple tuple = new CollectionTuple(collection);
                this.collectionStack.Push(tuple);
                this.FindNext(tuple);
            }