示例#1
0
        public TagInt AddInt(int val)
        {
            TagInt n = new TagInt(null, val);

            Add(n);
            return(n);
        }
示例#2
0
        public int GetInt(string name)
        {
            TagInt n = Get <TagInt>(name);

            return(n?.Value ?? 0);
        }
示例#3
0
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            int i = (int)indexes[0];

            if (i < 0 || i >= Count)
            {
                return(false);
            }

            if (value is INamedBinaryTag)
            {
                INamedBinaryTag nbt = value as INamedBinaryTag;
                if (nbt.TagType != GenericType)
                {
                    return(false);
                }

                Children[i] = nbt;
                return(true);
            }
            else if (value is byte && GenericType == ETagType.Byte)
            {
                Children[i] = new TagByte(null, (byte)value);
                return(true);
            }
            else if (value is sbyte && GenericType == ETagType.Byte)
            {
                Children[i] = new TagByte(null, (sbyte)value);
                return(true);
            }
            else if (value is short && GenericType == ETagType.Short)
            {
                Children[i] = new TagShort(null, (short)value);
                return(true);
            }
            else if (value is int && GenericType == ETagType.Int)
            {
                Children[i] = new TagInt(null, (int)value);
                return(true);
            }
            else if (value is long && GenericType == ETagType.Long)
            {
                Children[i] = new TagLong(null, (long)value);
                return(true);
            }
            else if (value is float && GenericType == ETagType.Float)
            {
                Children[i] = new TagFloat(null, (float)value);
                return(true);
            }
            else if (value is double && GenericType == ETagType.Double)
            {
                Children[i] = new TagDouble(null, (double)value);
                return(true);
            }
            else if (value is string && GenericType == ETagType.String)
            {
                Children[i] = new TagString(null, value as string);
                return(true);
            }
            else if (value is IEnumerable <byte> && GenericType == ETagType.Byte_Array)
            {
                TagByteArray ba = new TagByteArray(null);
                ba.AddRange(value as IEnumerable <byte>);
                Children[i] = ba;
                return(true);
            }
            else if (value is IEnumerable <sbyte> && GenericType == ETagType.Byte_Array)
            {
                TagByteArray ba = new TagByteArray(null);
                ba.AddRange(value as IEnumerable <sbyte>);
                Children[i] = ba;
                return(true);
            }
            else if (value is IEnumerable <int> && GenericType == ETagType.Int_Array)
            {
                TagIntArray ia = new TagIntArray(null);
                ia.AddRange(value as IEnumerable <int>);
                Children[i] = ia;
                return(true);
            }
            else if (value is IEnumerable <INamedBinaryTag> && GenericType == ETagType.List)
            {
                IEnumerable <INamedBinaryTag> coll = value as IEnumerable <INamedBinaryTag>;
                TagList list = new TagList(null);
                if (coll.Count() > 0)
                {
                    list.GenericType = coll.First().TagType;
                }
                else if (Count > 0 && this.First().TagType == ETagType.List)
                {
                    list.GenericType = this.First().TagType;
                }

                list.AddRange(coll);
                this[i] = list;
                return(true);
            }
            else
            {
                return(false);
            }
        }