示例#1
0
        /// <summary>
        /// Adds a child element to this collection.
        /// </summary>
        /// <param name="element">The element to add.</param>
        /// <exception cref="ArgumentException">Thrown if the child is not of an allowed type.</exception>
        public void AddElement(ISchemaElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            foreach (object obj in this.items)
            {
                bool containerUsed;

                if (obj is CollectionItem collectionItem)
                {
                    containerUsed = collectionItem.Elements.Count != 0;
                    if (collectionItem.ElementType.IsAssignableFrom(element.GetType()))
                    {
                        collectionItem.AddElement(element);

                        if (!containerUsed)
                        {
                            this.containersUsed++;
                        }

                        this.Count++;
                        return;
                    }

                    continue;
                }

                if (obj is ElementCollection collection)
                {
                    containerUsed = collection.Count != 0;

                    try
                    {
                        collection.AddElement(element);

                        if (!containerUsed)
                        {
                            this.containersUsed++;
                        }

                        this.Count++;
                        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));
        }
示例#2
0
        /// <summary>
        /// Adds a child element to this collection.
        /// </summary>
        /// <param name="element">The element to add.</param>
        /// <exception cref="ArgumentException">Thrown if the child is not of an allowed type.</exception>
        public void AddElement(ISchemaElement element)
        {
            foreach (object obj in this.items)
            {
                bool containerUsed;

                CollectionItem collectionItem = obj as CollectionItem;
                if (collectionItem != null)
                {
                    containerUsed = collectionItem.Elements.Count != 0;
                    if (collectionItem.ElementType.IsAssignableFrom(element.GetType()))
                    {
                        collectionItem.AddElement(element);

                        if (!containerUsed)
                        {
                            this.containersUsed++;
                        }

                        this.totalContainedItems++;
                        return;
                    }

                    continue;
                }

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

                    try
                    {
                        collection.AddElement(element);

                        if (!containerUsed)
                        {
                            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,
                                            WixStrings.EXP_ElementOfTypeIsNotValidForThisCollection,
                                            element.GetType().Name));
        }
示例#3
0
            public void RemoveElement(ISchemaElement element)
            {
                if (!elementType.IsAssignableFrom(element.GetType()))
                {
                    throw new ArgumentException(String.Format(
                                                    CultureInfo.InvariantCulture,
                                                    "Element must be a subclass of {0}, but was of type {1}.",
                                                    elementType.Name,
                                                    element.GetType().Name),
                                                "element");
                }

                this.elements.Remove(element);
            }
示例#4
0
            /// <summary>
            /// Removes an element from this collection.
            /// </summary>
            /// <param name="element">The element to remove.</param>
            /// <exception cref="ArgumentException">Thrown if the element's type isn't assignable to the collection's type.</exception>
            public void RemoveElement(ISchemaElement element)
            {
                if (!this.elementType.IsAssignableFrom(element.GetType()))
                {
                    throw new ArgumentException(
                              String.Format(
                                  CultureInfo.InvariantCulture,
                                  WixStrings.EXP_ElementIsSubclassOfDifferentType,
                                  this.elementType.Name,
                                  element.GetType().Name),
                              "element");
                }

                this.elements.Remove(element);
            }
示例#5
0
            /// <summary>
            /// Adds an element to this collection. Must be of an assignable type to the collection's
            /// type.
            /// </summary>
            /// <param name="element">The element to add.</param>
            /// <exception cref="ArgumentException">Thrown if the type isn't assignable to the collection's type.</exception>
            public void AddElement(ISchemaElement element)
            {
                if (element == null)
                {
                    throw new ArgumentNullException(nameof(element));
                }

                if (!this.elementType.IsAssignableFrom(element.GetType()))
                {
                    throw new ArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Element must be a subclass of {0}, but was of type {1}.",
                                  this.elementType.Name,
                                  element.GetType().Name),
                              nameof(element));
                }

                this.elements.Add(element);
            }
示例#6
0
        /// <summary>
        /// Sets an attribute on an ISchemaElement.
        /// </summary>
        /// <param name="schemaElement">Schema element to set attribute on.</param>
        /// <param name="name">Name of the attribute to set.</param>
        /// <param name="value">Value to set on the attribute.</param>
        private void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value)
        {
            ISetAttributes setAttributes = schemaElement as ISetAttributes;

            if (setAttributes == null)
            {
                throw new InvalidOperationException("ISchemaElement with name "
                                                    + schemaElement.GetType().FullName.ToString()
                                                    + " does not implement ISetAttributes.");
            }
            else
            {
                setAttributes.SetAttribute(name, value);
            }
        }
示例#7
0
        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));
        }
示例#8
0
        private static void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value)
        {
            ISetAttributes setAttributes = schemaElement as ISetAttributes;

            if (setAttributes == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixHarvesterStrings.EXP_ISchemaElementDoesnotImplementISetAttribute, schemaElement.GetType().FullName));
            }
            else
            {
                setAttributes.SetAttribute(name, value);
            }
        }
示例#9
0
 /// <summary>
 /// Sets an attribute on an ISchemaElement.
 /// </summary>
 /// <param name="schemaElement">Schema element to set attribute on.</param>
 /// <param name="name">Name of the attribute to set.</param>
 /// <param name="value">Value to set on the attribute.</param>
 private void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value)
 {
     ISetAttributes setAttributes = schemaElement as ISetAttributes;
     if (setAttributes == null)
     {
         throw new InvalidOperationException("ISchemaElement with name "
             + schemaElement.GetType().FullName.ToString()
             + " does not implement ISetAttributes.");
     }
     else
     {
         setAttributes.SetAttribute(name, value);
     }
 }
示例#10
0
            /// <summary>
            /// Removes an element from this collection.
            /// </summary>
            /// <param name="element">The element to remove.</param>
            /// <exception cref="ArgumentException">Thrown if the element's type isn't assignable to the collection's type.</exception>
            public void RemoveElement(ISchemaElement element)
            {
                if (!this.elementType.IsAssignableFrom(element.GetType()))
                {
                    throw new ArgumentException(
                        String.Format(
                            CultureInfo.InvariantCulture,
                            WixStrings.EXP_ElementIsSubclassOfDifferentType,
                            this.elementType.Name,
                            element.GetType().Name),
                        "element");
                }

                this.elements.Remove(element);
            }
示例#11
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,
                WixStrings.EXP_ElementOfTypeIsNotValidForThisCollection,
                element.GetType().Name));
        }
            /// <summary>
            /// Removes an element from this collection.
            /// </summary>
            /// <param name="element">The element to remove.</param>
            /// <exception cref="ArgumentException">Thrown if the element's type isn't assignable to the collection's type.</exception>
            public void RemoveElement(ISchemaElement element)
            {
                if (!this.elementType.IsAssignableFrom(element.GetType()))
                {
                    throw new ArgumentException(
                        String.Format(
                            CultureInfo.InvariantCulture,
                            "Element must be a subclass of {0}, but was of type {1}.",
                            this.elementType.Name,
                            element.GetType().Name),
                        "element");
                }

                this.elements.Remove(element);
            }
        /// <summary>
        /// Adds a child element to this collection.
        /// </summary>
        /// <param name="element">The element to add.</param>
        /// <exception cref="ArgumentException">Thrown if the child is not of an allowed type.</exception>
        public void AddElement(ISchemaElement element)
        {
            foreach (object obj in this.items)
            {
                bool containerUsed;

                CollectionItem collectionItem = obj as CollectionItem;
                if (collectionItem != null)
                {
                    containerUsed = collectionItem.Elements.Count != 0;
                    if (collectionItem.ElementType.IsAssignableFrom(element.GetType()))
                    {
                        collectionItem.AddElement(element);

                        if (!containerUsed)
                        {
                            this.containersUsed++;
                        }

                        this.totalContainedItems++;
                        return;
                    }

                    continue;
                }

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

                    try
                    {
                        collection.AddElement(element);

                        if (!containerUsed)
                        {
                            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));
        }
示例#14
0
 private static void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value)
 {
     ISetAttributes setAttributes = schemaElement as ISetAttributes;
     if (setAttributes == null)
     {
         throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixStrings.EXP_ISchemaElementDoesnotImplementISetAttribute, schemaElement.GetType().FullName));
     }
     else
     {
         setAttributes.SetAttribute(name, value);
     }
 }