Exemplo n.º 1
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,
                                                    WixDataStrings.EXP_CollectionMustHaveAtLeastOneElement,
                                                    elementCollection.Count));
                }

                CollectionTuple tuple = new CollectionTuple(elementCollection);

                this.collectionStack.Push(tuple);
                this.FindNext(tuple);
            }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new CollectionTuple.
 /// </summary>
 /// <param name="collection">The collection for the tuple.</param>
 public CollectionTuple(ElementCollection collection)
 {
     this.collection = collection;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a nested collection to this collection.
 /// </summary>
 /// <param name="collection">ElementCollection to add.</param>
 public void AddCollection(ElementCollection collection)
 {
     this.items.Add(collection);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new ElementCollectionEnumerator.
 /// </summary>
 /// <param name="collection">The collection to create an enumerator for.</param>
 public ElementCollectionEnumerator(ElementCollection collection)
 {
     this.collection = collection;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Removes a child element from this collection.
        /// </summary>
        /// <param name="element">The element to remove.</param>
        /// <exception cref="ArgumentException">Thrown if the element is not of an allowed type.</exception>
        public void RemoveElement(ISchemaElement element)
        {
            foreach (object obj in this.items)
            {
                CollectionItem collectionItem = obj as CollectionItem;
                if (collectionItem != null)
                {
                    if (collectionItem.ElementType.IsAssignableFrom(element.GetType()))
                    {
                        if (collectionItem.Elements.Count == 0)
                        {
                            return;
                        }

                        collectionItem.RemoveElement(element);

                        if (collectionItem.Elements.Count == 0)
                        {
                            this.containersUsed--;
                        }

                        this.totalContainedItems--;
                        return;
                    }

                    continue;
                }

                ElementCollection collection = obj as ElementCollection;
                if (collection != null)
                {
                    if (collection.Count == 0)
                    {
                        continue;
                    }

                    try
                    {
                        collection.RemoveElement(element);

                        if (collection.Count == 0)
                        {
                            this.containersUsed--;
                        }

                        this.totalContainedItems--;
                        return;
                    }
                    catch (ArgumentException)
                    {
                        // Eat the exception and keep looking. We'll throw our own if we can't find its home.
                    }

                    continue;
                }
            }

            throw new ArgumentException(String.Format(
                                            CultureInfo.InvariantCulture,
                                            WixDataStrings.EXP_ElementOfTypeIsNotValidForThisCollection,
                                            element.GetType().Name));
        }