Exemple #1
0
        //
        public void Set(int index, JToken value)
        {
            lock ((object)this)
            {
                // Make sure the property exists, filling in missing indexes
                if (Count <= index)
                {
                    while (Count < index)
                    {
                        Add(Tome.Conjure(JValue.CreateNull(), root));
                    }

                    Add(Tome.Conjure(value, root));
                    if (OnAdd != null)
                    {
                        OnAdd.Invoke(index);
                    }
                    return;
                }

                // Assign the property
                JToken property = this[index];
                switch (property.Type)
                {
                case JTokenType.Array:
                    ((TomeArray)property).Assign(value);
                    break;

                case JTokenType.Object:
                    ((TomeObject)property).Assign(value);
                    break;

                default:
                    var tomeValue = property as TomeValue;
                    if (tomeValue == null)
                    {
                        Mage.Instance.Logger("Tomes").Data(property).Error("property is not a tome value: " + index.ToString());
                        UnityEngine.Debug.Log(this);
                    }
                    else
                    {
                        tomeValue.Assign(value);
                    }
                    break;
                }
            }
        }
        //
        public void Set(string propertyName, JToken value)
        {
            lock ((object)this)
            {
                // Make sure the property exists
                if (this[propertyName] == null)
                {
                    Add(propertyName, Tome.Conjure(value, root));
                    if (OnAdd != null)
                    {
                        OnAdd.Invoke(propertyName);
                    }
                    return;
                }

                // Assign the property
                JToken property = this[propertyName];
                switch (property.Type)
                {
                case JTokenType.Array:
                    ((TomeArray)property).Assign(value);
                    break;

                case JTokenType.Object:
                    ((TomeObject)property).Assign(value);
                    break;

                default:
                    var tomeValue = property as TomeValue;
                    if (tomeValue == null)
                    {
                        Mage.Instance.Logger("Tomes").Data(property).Error("property is not a tome value: " + propertyName);
                        UnityEngine.Debug.Log(this);
                    }
                    else
                    {
                        tomeValue.Assign(value);
                    }
                    break;
                }
            }
        }