public virtual void WriteTag(ITag value, WriteTagOptions options) { if (value.Type != TagType.End && (options & WriteTagOptions.IgnoreName) == 0) { this.WriteHeader(value); } switch (value.Type) { case TagType.End: this.WriteEnd(); break; case TagType.Byte: this.WriteValue((byte)value.Value); break; case TagType.Short: this.WriteValue((short)value.Value); break; case TagType.Int: this.WriteValue((int)value.Value); break; case TagType.Long: this.WriteValue((long)value.Value); break; case TagType.Float: this.WriteValue((float)value.Value); break; case TagType.Double: this.WriteValue((double)value.Value); break; case TagType.ByteArray: this.WriteValue((byte[])value.Value); break; case TagType.String: this.WriteValue((string)value.Value); break; case TagType.List: this.WriteValue((TagCollection)value.Value); break; case TagType.Compound: this.WriteValue((TagDictionary)value.Value); break; case TagType.IntArray: this.WriteValue((int[])value.Value); break; default: throw new ArgumentException("Unrecognized or unsupported tag type.", nameof(value)); } }
public virtual void WriteTag(ITag value, WriteTagOptions options) { string name; name = value.Name; if (string.IsNullOrEmpty(name)) { name = "tag"; } if (XmlConvert.EncodeName(name) == name) { _writer.WriteStartElement(name); } else { _writer.WriteStartElement("tag"); _writer.WriteAttributeString("name", name); } if (value.Type != TagType.End && (options & WriteTagOptions.IgnoreName) == 0) { this.WriteHeader(value); } switch (value.Type) { case TagType.End: // noop break; case TagType.Byte: this.WriteValue((byte)value.Value); break; case TagType.Short: this.WriteValue((short)value.Value); break; case TagType.Int: this.WriteValue((int)value.Value); break; case TagType.Long: this.WriteValue((long)value.Value); break; case TagType.Float: this.WriteValue((float)value.Value); break; case TagType.Double: this.WriteValue((double)value.Value); break; case TagType.ByteArray: this.WriteValue((byte[])value.Value); break; case TagType.String: this.WriteValue((string)value.Value); break; case TagType.List: this.WriteValue((TagCollection)value.Value); break; case TagType.Compound: this.WriteValue((TagDictionary)value.Value); break; case TagType.IntArray: this.WriteValue((int[])value.Value); break; default: throw new ArgumentException("Unrecognized or unsupported tag type.", nameof(value)); } _writer.WriteEndElement(); }