public static XMLTypeHandler GetDerivedTypeHandlerFromXMLTag(XMLReader reader, out string tag)
        {
            tag = reader.SerializationReadTagAndTypeAttribute(out string typeAttribute);
            if (typeAttribute == null)
            {
                return(null);
            }
            Type derivedType = GetTypeByName(typeAttribute);

            if (derivedType != null)
            {
                return(GetTypeHandler(derivedType));
            }
            Engine.Log.Warning($"Couldn't find derived type of name {typeAttribute} in array.", MessageSource.XML);
            return(null);
        }
        /// <summary>
        /// Returns all elements contained in the xml.
        /// </summary>
        /// <returns>All elements contained in this xml.</returns>
        public List <XMLReader> Elements()
        {
            Reset();

            var result = new List <XMLReader>();

            while (!Finished)
            {
                XMLReader element = Element();
                if (element != null)
                {
                    result.Add(element);
                }
            }

            return(result);
        }
        /// <summary>
        /// Returns the next element with the specified tag name.
        /// </summary>
        /// <param name="tagName">The tag name to search for.</param>
        /// <returns></returns>
        public XMLReader NextElement(string tagName)
        {
            int       searchDepth = Depth;
            XMLReader foundTag    = null;

            while (!Finished)
            {
                // Only search at the same depth.
                if (Depth > searchDepth)
                {
                    ReadTagWithoutAttribute();
                    GoToNextTag();
                    continue;
                }

                if (foundTag != null)
                {
                    foundTag._length = _offset - foundTag._offset - 1;
                    return(foundTag);
                }

                // If found, record where it was found, and continue searching until we return to the same depth. Then we've found the closing tag.
                string tag = ReadTagWithAllAttributes(out Dictionary <string, string> lastAttributes);
                if (tagName == null || tag == tagName || tag == tagName + "/")
                {
                    foundTag = new XMLReader(_source, _offset + 1, Depth, lastAttributes)
                    {
                        Name = tagName ?? tag
                    }
                }
                ;
                GoToNextTag();
            }

            // Last element.
            if (Depth != searchDepth || foundTag == null)
            {
                return(null);
            }
            foundTag._length = _offset - foundTag._offset - 1;
            return(foundTag);
        }