Ejemplo n.º 1
0
        public override void WriteEndTag()
        {
            TagType currentTag;

            currentTag = _state.CurrentTag;

            if ((currentTag == TagType.ByteArray || currentTag == TagType.IntArray) && _arraySb != null && _arraySb.Length != 0)
            {
                _writer.WriteValue(_arraySb.ToString());
                _arraySb.Length = 0;
            }

            _state.EndTag();

            _writer.WriteEndElement();
        }
Ejemplo n.º 2
0
        private Tag ReadTag(TagType defaultTagType)
        {
            Tag               result;
            TagType           type;
            string            name;
            TagContainerState state;

            type = this.ReadTagType(defaultTagType);

            state = _state.StartTag(type);

            if (type != TagType.End && (state == null || state.ContainerType != TagType.List))
            {
                name = _reader.GetAttribute("name");
                if (string.IsNullOrEmpty(name))
                {
                    name = this.ReadTagName();
                }
            }
            else
            {
                name = string.Empty;
            }

            result = null;

            switch (type)
            {
            case TagType.Byte:
                result = TagFactory.CreateTag(name, this.ReadByte());
                break;

            case TagType.Short:
                result = TagFactory.CreateTag(name, this.ReadShort());
                break;

            case TagType.Int:
                result = TagFactory.CreateTag(name, this.ReadInt());
                break;

            case TagType.Long:
                result = TagFactory.CreateTag(name, this.ReadLong());
                break;

            case TagType.Float:
                result = TagFactory.CreateTag(name, this.ReadFloat());
                break;

            case TagType.Double:
                result = TagFactory.CreateTag(name, this.ReadDouble());
                break;

            case TagType.ByteArray:
                result = TagFactory.CreateTag(name, this.ReadByteArray());
                break;

            case TagType.String:
                result = TagFactory.CreateTag(name, this.ReadString());
                break;

            case TagType.List:
                result = TagFactory.CreateTag(name, this.ReadList());
                break;

            case TagType.Compound:
                result = TagFactory.CreateTag(name, this.ReadCompound());
                break;

            case TagType.IntArray:
                result = TagFactory.CreateTag(name, this.ReadIntArray());
                break;

                // Can't be hit as ReadTagType will throw
                // an exception for unsupported types
                // default:
                //   throw new InvalidDataException($"Unrecognized tag type: {type}");
            }

            _state.EndTag();

            return(result);
        }
Ejemplo n.º 3
0
 public override void WriteEndTag()
 {
     _state.EndTag(this.WriteEnd);
 }
Ejemplo n.º 4
0
        public override TagCollection ReadList()
        {
            TagCollection tags;
            int           length;
            TagType       listType;

            listType = (TagType)this.ReadByte();

            if (listType < TagType.Byte || listType > TagType.IntArray)
            {
                throw new InvalidDataException($"Unexpected list type '{listType}' found.");
            }

            tags   = new TagCollection(listType);
            length = this.ReadInt();

            for (int i = 0; i < length; i++)
            {
                Tag tag;

                tag = null;

                _state.StartTag(listType);

                switch (listType)
                {
                case TagType.Byte:
                    tag = TagFactory.CreateTag(this.ReadByte());
                    break;

                case TagType.ByteArray:
                    tag = TagFactory.CreateTag(this.ReadByteArray());
                    break;

                case TagType.Compound:
                    tag = TagFactory.CreateTag(this.ReadCompound());
                    break;

                case TagType.Double:
                    tag = TagFactory.CreateTag(this.ReadDouble());
                    break;

                case TagType.Float:
                    tag = TagFactory.CreateTag(this.ReadFloat());
                    break;

                case TagType.Int:
                    tag = TagFactory.CreateTag(this.ReadInt());
                    break;

                case TagType.IntArray:
                    tag = TagFactory.CreateTag(this.ReadIntArray());
                    break;

                case TagType.List:
                    tag = TagFactory.CreateTag(this.ReadList());
                    break;

                case TagType.Long:
                    tag = TagFactory.CreateTag(this.ReadLong());
                    break;

                case TagType.Short:
                    tag = TagFactory.CreateTag(this.ReadShort());
                    break;

                case TagType.String:
                    tag = TagFactory.CreateTag(this.ReadString());
                    break;

                    // Can never be hit due to the type check above
                    //default:
                    //  throw new InvalidDataException("Invalid list type.");
                }

                _state.EndTag();

                tags.Add(tag);
            }

            return(tags);
        }