Example #1
0
        public ITag Add(string name, byte[] value)
        {
            ITag tag;

            tag = new TagByteArray(name, value);

            this.Add(tag);

            return(tag);
        }
Example #2
0
        public static ITag CreateTag(TagType tagType, string name, object defaultValue)
        {
            ITag result;

              switch (tagType)
              {
            case TagType.Byte:
              result = new TagByte();
              break;

            case TagType.Short:
              result = new TagShort();
              break;

            case TagType.Int:
              result = new TagInt();
              break;

            case TagType.Long:
              result = new TagLong();
              break;

            case TagType.Float:
              result = new TagFloat();
              break;

            case TagType.Double:
              result = new TagDouble();
              break;

            case TagType.ByteArray:
              result = new TagByteArray();
              break;

            case TagType.String:
              result = new TagString();
              break;

            case TagType.List:
              result = new TagList();
              break;

            case TagType.Compound:
              result = new TagCompound();
              break;

            case TagType.IntArray:
              result = new TagIntArray();
              break;

            case TagType.End:
              result = new TagEnd();
              break;

            default:
              throw new ArgumentException(string.Format("Unrecognized tag type: {0}", tagType));
              }

              result.Name = name;
              if (defaultValue != null)
              {
            result.Value = defaultValue;
              }

              return result;
        }
Example #3
0
        /// <summary>
        /// Creates a tag for the specified parameters.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown if <paramref name="tagType"/> is not valid.</exception>
        /// <param name="tagType">Type of the tag to create.</param>
        /// <param name="name">The name of the tag create.</param>
        /// <param name="listType">The type of items a list holds.</param>
        /// <returns>
        /// A new tag using the specified parameters.
        /// </returns>
        public static Tag CreateTag(string name, TagType tagType, TagType listType)
        {
            Tag result;

            if (tagType != TagType.List)
            {
                if (listType != TagType.None)
                {
                    throw new ArgumentException("Only lists can have a list type.", nameof(listType));
                }

                switch (tagType)
                {
                case TagType.Byte:
                    result = new TagByte(name);
                    break;

                case TagType.Short:
                    result = new TagShort(name);
                    break;

                case TagType.Int:
                    result = new TagInt(name);
                    break;

                case TagType.Long:
                    result = new TagLong(name);
                    break;

                case TagType.Float:
                    result = new TagFloat(name);
                    break;

                case TagType.Double:
                    result = new TagDouble(name);
                    break;

                case TagType.ByteArray:
                    result = new TagByteArray(name);
                    break;

                case TagType.String:
                    result = new TagString(name);
                    break;

                case TagType.Compound:
                    result = new TagCompound(name);
                    break;

                case TagType.IntArray:
                    result = new TagIntArray(name);
                    break;

                case TagType.End:
                    result = new TagEnd();
                    break;

                default:
                    throw new ArgumentException("Unrecognized or unsupported tag type.", nameof(tagType));
                }
            }
            else
            {
                result = new TagList(name, listType);
            }

            return(result);
        }