상속: ITagWriter
예제 #1
0
        public static TagWriter CreateWriter(NbtFormat format, Stream stream)
        {
            TagWriter writer;

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            switch (format)
            {
            case NbtFormat.Binary:
                writer = new BinaryTagWriter(stream);
                break;

            case NbtFormat.Xml:
                writer = new XmlTagWriter(stream);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, "Invalid format.");
            }

            return(writer);
        }
    public void WriteEmptyByteArrayTest()
    {
      // arrange
      ITagWriter target;
      NbtDocument expected;
      MemoryStream stream;
      ITagReader reader;

      expected = new NbtDocument();
      expected.DocumentRoot.Name = "WriteEmptyByteArrayTest";
      expected.DocumentRoot.Value.Add("ByteArray", new byte[0]);
      expected.DocumentRoot.Value.Add("Byte", 255);

      stream = new MemoryStream();

      target = new BinaryTagWriter(stream);

      // act
      target.WriteTag(expected.DocumentRoot, WriteTagOptions.None);

      // assert
      stream.Seek(0, SeekOrigin.Begin);
      reader = new BinaryTagReader(stream);
      this.CompareTags(expected.DocumentRoot, reader.ReadTag());
    }