예제 #1
0
        //if value is null, calls RemoveTag, also performs type checking
        public void Set(string key, object value, bool replace = false)
        {
            if (value == null)
            {
                Remove(key);
                return;
            }

            object serialized;

            try {
                serialized = TagIO.Serialize(value);
            }
            catch (IOException e) {
                var valueInfo = "value=" + value;
                if (value.GetType().ToString() != value.ToString())
                {
                    valueInfo = "type=" + value.GetType() + "," + valueInfo;
                }
                throw new IOException($"NBT Serialization (key={key},{valueInfo})", e);
            }
            if (replace)
            {
                dict[key] = serialized;
            }
            else
            {
                dict.Add(key, serialized);
            }
        }
예제 #2
0
        //if value is null, calls RemoveTag, also performs type checking
        public void Set(string key, object value)
        {
            if (value == null)
            {
                Remove(key);
                return;
            }

            try {
                dict.Add(key, TagIO.Serialize(value));
            }
            catch (IOException e) {
                var valueInfo = "value=" + value;
                if (value.GetType().ToString() != value.ToString())
                {
                    valueInfo = "type=" + value.GetType() + "," + valueInfo;
                }
                throw new IOException($"NBT Serialization (key={key},{valueInfo})", e);
            }
        }