//public void MergeToObject(IExtendedDatas instance, RunContext ctx = null) //{ // var properties = TypeDiscovery.Instance.GetProperties(instance.GetType()); // foreach (var item in this.Items) // if (properties.TryGetValue(item.Key, out AccessorItem acc)) // { // //acc.Type // var txt = item.Value.Serialize(ctx); // } // else // instance.ExtendedDatas.Add(item.Key, item.Value.Clone()); //} public DynObject Merge(DynObject o) { if (o.GetValue != null) { if (this.GetValue != null) { throw new Exceptions.ConflictMergeDynObjectException("object can't be merged because the value is not empty."); } else { GetValue = o.GetValue; } } else { foreach (var item in o.Items) { if (Items.TryGetValue(item.Key, out DynObject o2)) { o2.Merge(item.Value); } else { Items.Add(item.Key, item.Value); } } } return(this); }
public DynObject AddSub(string key, IDictionary <string, DynObject> arguments) { var arg = new DynObject(); this.Items.Add(key, arg); if (arguments != null) { foreach (var item in arguments) { arg.Add(item.Key, item.Value); } } return(arg); }
public DynObject Clone() { var r = new DynObject() { GetValue = this.GetValue, IsArray = IsArray, }; foreach (var item in Items) { r.Items.Add(item.Key, item.Value.Clone()); } return(r); }
public static DynObject Create(string key, DynObject value) { return(new DynObject() .Add(key, value)); }
public DynObject Add(string key, DynObject value) { this.Items.Add(key, value); return(this); }