Absorb() public méthode

public Absorb ( JSONObject, obj ) : void
obj JSONObject,
Résultat void
Exemple #1
0
 /// <summary>
 /// Merge object right into left recursively
 /// </summary>
 /// <param name="left">The left (base) object</param>
 /// <param name="right">The right (new) object</param>
 static void MergeRecur(JSONObject left, JSONObject right)
 {
     if (left.type == Type.NULL)
     {
         left.Absorb(right);
     }
     else if (left.type == Type.OBJECT && right.type == Type.OBJECT)
     {
         for (int i = 0; i < right.list.Count; i++)
         {
             string key = right.keys[i];
             if (right[i].isContainer)
             {
                 if (left.HasField(key))
                 {
                     MergeRecur(left[key], right[i]);
                 }
                 else
                 {
                     left.AddField(key, right[i]);
                 }
             }
             else
             {
                 if (left.HasField(key))
                 {
                     left.SetField(key, right[i]);
                 }
                 else
                 {
                     left.AddField(key, right[i]);
                 }
             }
         }
     }
     else if (left.type == Type.ARRAY && right.type == Type.ARRAY)
     {
         if (right.Count > left.Count)
         {
             Debug.LogError("Cannot merge arrays when right object has more elements");
             return;
         }
         for (int i = 0; i < right.list.Count; i++)
         {
             if (left[i].type == right[i].type)                                      //Only overwrite with the same type
             {
                 if (left[i].isContainer)
                 {
                     MergeRecur(left[i], right[i]);
                 }
                 else
                 {
                     left[i] = right[i];
                 }
             }
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// Merge object right into left recursively
 /// </summary>
 /// <param name="left">The left (base) object</param>
 /// <param name="right">The right (new) object</param>
 static void MergeRecur(JSONObject left, JSONObject right)
 {
     if (left.type == Type.NULL)
     {
         left.Absorb(right);
     }
     else if (left.type == Type.OBJECT && right.type == Type.OBJECT)
     {
         for (int i = 0; i < right.list.Count; i++)
         {
             string key = right.keys[i];
             if (right[i].isContainer)
             {
                 if (left.HasField(key))
                 {
                     MergeRecur(left[key], right[i]);
                 }
                 else
                 {
                     left.AddField(key, right[i]);
                 }
             }
             else
             {
                 if (left.HasField(key))
                 {
                     left.SetField(key, right[i]);
                 }
                 else
                 {
                     left.AddField(key, right[i]);
                 }
             }
         }
     }
     else if (left.type == Type.ARRAY && right.type == Type.ARRAY)
     {
         if (right.Count > left.Count)
         {
             return;
         }
         for (int i = 0; i < right.list.Count; i++)
         {
             if (left[i].type == right[i].type)
             {           //Only overwrite with the same type
                 if (left[i].isContainer)
                 {
                     MergeRecur(left[i], right[i]);
                 }
                 else
                 {
                     left[i] = right[i];
                 }
             }
         }
     }
 }
Exemple #3
0
	/// <summary>
	/// Merge object right into left recursively
	/// </summary>
	/// <param name="left">The left (base) object</param>
	/// <param name="right">The right (new) object</param>
	static void MergeRecur(JSONObject left, JSONObject right) {
		if(left.type == JSONObject.Type.NULL)
			left.Absorb(right);
		else if(left.type == Type.OBJECT && right.type == Type.OBJECT) {
			for(int i = 0; i < right.list.Count; i++) {
				string key = (string)right.keys[i];
				if(right[i].isContainer){
					if(left.HasField(key))
						MergeRecur(left[key], right[i]);
					else
						left.AddField(key, right[i]);
				} else {
					if(left.HasField(key))
						left.SetField(key, right[i]);
					else
						left.AddField(key, right[i]);
				}
			}
		} else if(left.type == Type.ARRAY && right.type == Type.ARRAY) {
			if(right.Count > left.Count){
				Debug.LogError("Cannot merge arrays when right object has more elements");
				return;
			}
			for(int i = 0; i < right.list.Count; i++) {
				if(left[i].type == right[i].type) {			//Only overwrite with the same type
					if(left[i].isContainer)
						MergeRecur(left[i], right[i]);
					else{
						left[i] = right[i];
					}
				}
			}
		}
	}
    /// <summary>
    ///     Merge object right into left recursively
    /// </summary>
    /// <param name="left">The left (base) object</param>
    /// <param name="right">The right (new) object</param>
    private static void MergeRecur(JSONObject left, JSONObject right)
    {
        if (left.type == Type.NULL)
        {
            left.Absorb(right);
        }
        else if (left.type == Type.OBJECT && right.type == Type.OBJECT)
        {
            for (var i = 0; i < right.list.Count; i++)
            {
                var key = right.keys[i];
                if (right[i].isContainer)
                {
                    if (left.HasField(key))
                    {
                        MergeRecur(left[key], right[i]);
                    }
                    else
                    {
                        left.AddField(key, right[i]);
                    }
                }
                else
                {
                    if (left.HasField(key))
                    {
                        left.SetField(key, right[i]);
                    }
                    else
                    {
                        left.AddField(key, right[i]);
                    }
                }
            }
        }
        else if (left.type == Type.ARRAY && right.type == Type.ARRAY)
        {
            if (right.Count > left.Count)
            {
#if UNITY_2 || UNITY_3 || UNITY_4 || UNITY_5
                Debug.LogError
#else
                Debug.WriteLine
#endif
                    ("Cannot merge arrays when right object has more elements");

                return;
            }

            for (var i = 0; i < right.list.Count; i++)
            {
                if (left[i].type == right[i].type)
                {
                    //Only overwrite with the same type
                    if (left[i].isContainer)
                    {
                        MergeRecur(left[i], right[i]);
                    }
                    else
                    {
                        left[i] = right[i];
                    }
                }
            }
        }
    }
Exemple #5
0
	/// <summary>
	/// Merge object right into left recursively
	/// </summary>
	/// <param name="left">The left (base) object</param>
	/// <param name="right">The right (new) object</param>
	static void MergeRecur(JSONObject left, JSONObject right) {
		if(left.type == Type.NULL)
			left.Absorb(right);
		else if(left.type == Type.OBJECT && right.type == Type.OBJECT) {
			for(int i = 0; i < right.list.Count; i++) {
				string key = right.keys[i];
				if(right[i].isContainer) {
					if(left.HasField(key))
						MergeRecur(left[key], right[i]);
					else
						left.AddField(key, right[i]);
				} else {
					if(left.HasField(key))
						left.SetField(key, right[i]);
					else
						left.AddField(key, right[i]);
				}
			}
		} else if(left.type == Type.ARRAY && right.type == Type.ARRAY) {
			if(right.Count > left.Count) {
				return;
			}
			for(int i = 0; i < right.list.Count; i++) {
				if(left[i].type == right[i].type) {			//Only overwrite with the same type
					if(left[i].isContainer)
						MergeRecur(left[i], right[i]);
					else {
						left[i] = right[i];
					}
				}
			}
		}
	}