Example #1
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);
        }
Example #2
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);
        }