// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. namespace WixToolset.Data.WindowsInstaller { using System.Xml; /// /// Substorage inside an output. /// public sealed class SubStorage { /// /// Instantiate a new substorage. /// /// The substorage name. /// The substorage data. public SubStorage(string name, WindowsInstallerData data) { this.Name = name; this.Data = data; } /// /// Gets the substorage name. /// /// The substorage name. public string Name { get; } /// /// Gets the substorage data. /// /// The substorage data. public WindowsInstallerData Data { get; } /// /// Creates a SubStorage from the XmlReader. /// /// Reader to get data from. /// Table definitions to use for strongly-typed rows. /// New SubStorage object. internal static SubStorage Read(XmlReader reader, TableDefinitionCollection tableDefinitions) { if (reader.LocalName != "subStorage") { throw new XmlException(); } WindowsInstallerData data = null; string name = null; var empty = reader.IsEmptyElement; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "name": name = reader.Value; break; } } if (!empty) { var done = false; while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case WindowsInstallerData.XmlElementName: data = WindowsInstallerData.Read(reader, tableDefinitions, true); break; default: throw new XmlException(); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new XmlException(); } } return new SubStorage(name, data); } /// /// Persists a SubStorage in an XML format. /// /// XmlWriter where the SubStorage should persist itself as XML. internal void Write(XmlWriter writer) { writer.WriteStartElement("subStorage", WindowsInstallerData.XmlNamespaceUri); writer.WriteAttributeString("name", this.Name); this.Data.Write(writer); writer.WriteEndElement(); } } }