Exemple #1
0
        public IEnumerable Filter(Type childType)
        {
            foreach (object container in this.items)
            {
                CollectionItem collectionItem = container as CollectionItem;
                if (collectionItem != null)
                {
                    if (collectionItem.ElementType.IsAssignableFrom(childType))
                    {
                        return(collectionItem.Elements);
                    }

                    continue;
                }

                ElementCollection elementCollection = container as ElementCollection;
                if (elementCollection != null)
                {
                    IEnumerable nestedFilter = elementCollection.Filter(childType);
                    if (nestedFilter != null)
                    {
                        return(nestedFilter);
                    }

                    continue;
                }
            }

            return(null);
        }
        /// <summary>
        /// Gets an enumerable collection of children of a given type.
        /// </summary>
        /// <param name="childType">Type of children to get.</param>
        /// <returns>A collection of children.</returns>
        /// <exception cref="ArgumentException">Thrown if the type isn't a valid child type.</exception>
        public IEnumerable Filter(Type childType)
        {
            foreach (object container in this.items)
            {
                CollectionItem collectionItem = container as CollectionItem;
                if (collectionItem != null)
                {
                    if (collectionItem.ElementType.IsAssignableFrom(childType))
                    {
                        return(collectionItem.Elements);
                    }

                    continue;
                }

                ElementCollection elementCollection = container as ElementCollection;
                if (elementCollection != null)
                {
                    IEnumerable nestedFilter = elementCollection.Filter(childType);
                    if (nestedFilter != null)
                    {
                        return(nestedFilter);
                    }

                    continue;
                }
            }

            throw new ArgumentException(String.Format(
                                            CultureInfo.InvariantCulture,
                                            "Type {0} is not valid for this collection.",
                                            childType.Name));
        }