// Copyright (c) Craftwork Games. All rights reserved. // Licensed under the MIT license. // See LICENSE file in the project root for full license information. using System; using System.Xml; using Microsoft.Xna.Framework; namespace MonoGame.Extended.Serialization.Xml; /// /// Provides extension methods for to simplify writing XML attributes from strongly-typed values /// public static class XmlWriterExtensions { /// /// Writes an XML attribute from an value. /// /// The XML writer instance. /// The name of the attribute to write. /// The value to write as the attribute value. /// The writer state is not valid for this operation. /// The attribute name is not valid. public static void WriteAttributeInt(this XmlWriter writer, string attributeName, int value) { writer.WriteAttributeString(attributeName, $"{value}"); } /// /// Writes an XML attribute from a value. /// /// The XML writer instance. /// The name of the attribute to write. /// The value to write as the attribute value. /// The writer state is not valid for this operation. /// The attribute name is not valid. public static void WriteAttributeFloat(this XmlWriter writer, string attributeName, float value) { writer.WriteAttributeString(attributeName, $"{value}"); } /// /// Writes an XML attribute from a value. /// /// The XML writer instance. /// The name of the attribute to write. /// The value to write as the attribute value. /// The writer state is not valid for this operation. /// The attribute name is not valid. public static void WriteAttributeBool(this XmlWriter writer, string attributeName, bool value) { writer.WriteAttributeString(attributeName, $"{value}"); } /// /// Writes an XML attribute from a value. /// /// The XML writer instance. /// The name of the attribute to write. /// The value to write as the attribute value. /// The writer state is not valid for this operation. /// The attribute name is not valid. public static void WriteAttributeRectangle(this XmlWriter writer, string attributeName, Rectangle value) { writer.WriteAttributeString(attributeName, $"{value.X},{value.Y},{value.Width},{value.Height}"); } /// /// Writes an XML attribute from a value. /// /// The XML writer instance. /// The name of the attribute to write. /// The value to write as the attribute value. /// The writer state is not valid for this operation. /// The attribute name is not valid. public static void WriteAttributeVector2(this XmlWriter writer, string attributeName, Vector2 value) { writer.WriteAttributeString(attributeName, $"{value.X},{value.Y}"); } /// /// Writes an XML attribute from a value. /// /// The XML writer instance. /// The name of the attribute to write. /// The value to write as the attribute value. /// The writer state is not valid for this operation. /// The attribute name is not valid. public static void WriteAttributeVector3(this XmlWriter writer, string attributeName, Vector3 value) { writer.WriteAttributeString(attributeName, $"{value.X},{value.Y},{value.Z}"); } }