/// <summary>
        /// Serialize this object's properties to XML.
        /// </summary>
        /// <param name="writer">Destination to write XML to.</param>
        public void WriteXml(XmlWriter writer)
        {
            if (writer is null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            writer.WriteAttributeString("Id", Id);
            if (Headcode != null)
            {
                writer.WriteElementString("Headcode", Headcode);
            }
            if (LocoDiagram != null)
            {
                writer.WriteElementString("LocoDiagram", LocoDiagram);
            }
            if (TrainClassId != null)
            {
                writer.WriteElementString("TrainClassId", TrainClassId);
            }

            if (GraphProperties != null)
            {
                writer.WriteStartElement("GraphProperties");
                GraphProperties.WriteXml(writer);
                writer.WriteEndElement();
            }

            writer.WriteStartElement("TrainTimes");
            foreach (TrainLocationTimeModel time in TrainTimes)
            {
                writer.WriteStartElement("Time");
                time.WriteXml(writer);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteStartElement("FootnoteIds");
            foreach (string note in FootnoteIds)
            {
                writer.WriteElementString("Note", note);
            }
            writer.WriteEndElement();

            writer.WriteElementString("IncludeSeparatorAbove", IncludeSeparatorAbove ? "true" : "false");
            writer.WriteElementString("IncludeSeparatorBelow", IncludeSeparatorBelow ? "true" : "false");
            writer.WriteElementString("InlineNote", InlineNote);

            if (ToWork != null)
            {
                writer.WriteStartElement("ToWork");
                ToWork.WriteXml(writer);
                writer.WriteEndElement();
            }
            if (LocoToWork != null)
            {
                writer.WriteStartElement("LocoToWork");
                LocoToWork.WriteXml(writer);
                writer.WriteEndElement();
            }
        }