コード例 #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,
                                                    WixHarvesterStrings.EXP_CollectionMustHaveAtLeastOneElement,
                                                    elementCollection.Count));
                }

                CollectionSymbol symbol = new CollectionSymbol(elementCollection);

                this.collectionStack.Push(symbol);
                this.FindNext(symbol);
            }
コード例 #2
0
 /// <summary>
 /// Creates a new CollectionSymbol.
 /// </summary>
 /// <param name="collection">The collection for the symbol.</param>
 public CollectionSymbol(ElementCollection collection)
 {
     this.collection = collection;
 }
コード例 #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);
 }
コード例 #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;
 }
コード例 #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,
                                            WixHarvesterStrings.EXP_ElementOfTypeIsNotValidForThisCollection,
                                            element.GetType().Name));
        }