/// <summary>
        /// Construct a new ParentedEXmlObject from an existing Base.
        /// </summary>
        /// <param name="baseObject">The existing base.</param>
        protected ParentedEXmlObject(EXmlBase baseObject)
        {
            Name     = baseObject.Name;
            Elements = baseObject.Elements;
            Children = new List <ParentedEXmlObject>();
            EXmlData     data = baseObject as EXmlData;
            EXmlMeta     meta = baseObject as EXmlMeta;
            EXmlProperty prop = baseObject as EXmlProperty;

            if (data != null)
            {
                Attribute = new EXmlAttribute {
                    AttributeName = "template",
                    Value         = data.Template
                };
            }
            else if (meta != null)
            {
                Attribute = new EXmlAttribute {
                    AttributeName = "comment",
                    Value         = meta.Comment,
                };
            }
            else if (prop != null)
            {
                Attribute = new EXmlAttribute {
                    AttributeName = "value",
                    Value         = prop.Value
                };
            }
            else
            {
                Attribute = null;
            }
        }
        /// <summary>
        /// Converts this custom object back into an EXmlBase so that it can be serialized back into an MBIN.
        /// </summary>
        /// <returns></returns>
        public EXmlBase ConvertToSerializableEXML(EXmlBase parent = null, ParentedEXmlObject parentAsNative = null)
        {
            EXmlBase root;

            if (parent == null)
            {
                // Attribute is gonna be template. If it's not, there's a problem.
                if (Attribute.AttributeName != "template")
                {
                    throw new Exception("Top level attribute is not a template!");
                }
                EXmlData newData = new EXmlData();
                newData.Name     = Name;
                newData.Template = Attribute.Value;
                root             = newData;
            }
            else
            {
                root = parent;
            }

            //EXmlBase root = parent ?? this;
            parentAsNative = parentAsNative ?? this;
            root.Elements  = new List <EXmlBase>();
            foreach (ParentedEXmlObject child in parentAsNative.Children)
            {
                EXmlBase childAsBase = child;
                if (child.Attribute?.AttributeName == "template")
                {
                    EXmlData childAsTyped = new EXmlData();
                    childAsTyped.Name     = childAsBase.Name;
                    childAsTyped.Elements = childAsBase.Elements;
                    childAsTyped.Template = child.Attribute.Value;
                    root.Elements.Add(childAsTyped);
                    childAsBase = childAsTyped;
                }
                else if (child.Attribute?.AttributeName == "value")
                {
                    EXmlProperty childAsTyped = new EXmlProperty();
                    childAsTyped.Name     = childAsBase.Name;
                    childAsTyped.Elements = childAsBase.Elements;
                    childAsTyped.Value    = child.Attribute.Value;
                    root.Elements.Add(childAsTyped);
                    childAsBase = childAsTyped;
                }
                else if (child.Attribute?.AttributeName == "comment")
                {
                    EXmlMeta childAsTyped = new EXmlMeta();
                    childAsTyped.Name     = childAsBase.Name;
                    childAsTyped.Elements = childAsBase.Elements;
                    childAsTyped.Comment  = child.Attribute.Value;
                    root.Elements.Add(childAsTyped);
                    childAsBase = childAsTyped;
                }
                else
                {
                    root.Elements.Add(childAsBase);
                }

                ConvertToSerializableEXML(childAsBase, child);
            }
            return(root);
        }