public void TestWalkProperties()
        {
            Kml kml = new Kml();
            kml.Feature = new Folder(); // This will not be added to the Children collection

            Assert.That(ElementWalker.Walk(kml).Count(), Is.EqualTo(2));
        }
        /// <summary>
        /// Provides a way to iterate over all children <see cref="Element"/>s
        /// contained by this instance.
        /// </summary>
        /// <param name="element">The class instance.</param>
        /// <returns>An IEnumerable&lt;Element&gt; for specified element.</returns>
        /// <exception cref="ArgumentNullException">element is null.</exception>
        public static IEnumerable <Element> Flatten(this Element element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            return(ElementWalker.Walk(element));
        }
        public void TestWalkChildren()
        {
            const int Depth = 50;

            Folder parent = new Folder();
            Folder root = parent;
            for (int i = 0; i < Depth; ++i)
            {
                Folder child = new Folder();
                parent.AddFeature(child); // Added to the Children collection
                parent = child;
            }

            Assert.That(ElementWalker.Walk(root).Count(), Is.EqualTo(Depth + 1)); // Depth + 1 to allow for root itself
        }
        public void TestWalkCustomElements()
        {
            const int Count = 10;
            CoordinateCollection coordinates = new CoordinateCollection();
            for (int i = 0; i < Count; ++i)
            {
                coordinates.Add(new Vector());
            }
            Assert.That(ElementWalker.Walk(coordinates).Count(), Is.EqualTo(1));

            // This class uses a private class deriving from ICustomElement as a child
            // Make sure it's not included.
            ItemIcon icon = new ItemIcon();
            icon.State = ItemIconStates.Open | ItemIconStates.Error;
            Assert.That(ElementWalker.Walk(icon).Count(), Is.EqualTo(1));
        }
Beispiel #5
0
        /// <summary>
        /// Creates a KmlFie from the specified <see cref="Element"/> hierarchy.
        /// </summary>
        /// <param name="root">The root <c>Element</c> of the file.</param>
        /// <param name="duplicates">
        /// true to allow duplicate <see cref="KmlObject.Id"/> values (newer
        /// values will overwrite existing values); false to throw an exception
        /// for duplicate values.
        /// </param>
        /// <returns>
        /// A new KmlFile with the specified <c>Element</c> as the root.
        /// </returns>
        /// <exception cref="ArgumentNullException">root is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// A object has already been registered with the same Id and the
        /// duplicates argument is set to false.
        /// </exception>
        public static KmlFile Create(Element root, bool duplicates)
        {
            Check.IsNotNull(root, nameof(root));

            var file = new KmlFile
            {
                strict = !duplicates,
            };

            foreach (Element element in ElementWalker.Walk(root))
            {
                file.OnElementAdded(element);
            }

            file.Root = root;
            return(file);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a KmlFie from the specified <see cref="Element"/> hierarchy.
        /// </summary>
        /// <param name="root">The root <c>Element</c> of the file.</param>
        /// <param name="duplicates">
        /// true to allow duplicate <see cref="KmlObject.Id"/> values (newer
        /// values will overwrite existing values); false to throw an exception
        /// for duplicate values.
        /// </param>
        /// <returns>
        /// A new KmlFile with the specified <c>Element</c> as the root.
        /// </returns>
        /// <exception cref="ArgumentNullException">root is null.</exception>
        /// <exception cref="InvalidOperationException">
        /// A object has already been registered with the same Id and the
        /// duplicates argument is set to false.
        /// </exception>
        public static KmlFile Create(Element root, bool duplicates)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            KmlFile file = new KmlFile();

            file.strict = !duplicates;

            foreach (var element in ElementWalker.Walk(root))
            {
                file.OnElementAdded(element);
            }

            file.Root = root;
            return(file);
        }
Beispiel #7
0
        /// <summary>
        /// Provides a way to iterate over all children <see cref="Element"/>s
        /// contained by this instance.
        /// </summary>
        /// <param name="element">The class instance.</param>
        /// <returns>An IEnumerable&lt;Element&gt; for specified element.</returns>
        /// <exception cref="ArgumentNullException">element is null.</exception>
        public static IEnumerable <Element> Flatten(this Element element)
        {
            Check.IsNotNull(element, nameof(element));

            return(ElementWalker.Walk(element));
        }