Exemple #1
0
            /// <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);
            }
Exemple #2
0
 /// <summary>
 /// Creates a new CollectionTuple.
 /// </summary>
 /// <param name="collection">The collection for the tuple.</param>
 public CollectionTuple(ElementCollection collection)
 {
     this.collection = collection;
 }
Exemple #3
0
 /// <summary>
 /// Adds a nested collection to this collection.
 /// </summary>
 /// <param name="collection">ElementCollection to add.</param>
 internal void AddCollection(ElementCollection collection)
 {
     this.items.Add(collection);
 }
Exemple #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;
 }
Exemple #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,
                                            "Element of type {0} is not valid for this collection.",
                                            element.GetType().Name));
        }