public override bool Equals(object rval) { if (!(rval is DictValue)) { return(false); } DictValue dict = (DictValue)rval; if (this.Count != dict.Count) { return(false); } foreach (TextValue key in this.Keys) { if (!dict.ContainsKey(key)) { return(false); } Object lival = this[key]; Object rival = dict[key]; if (!lival.Equals(rival)) { return(false); } } return(true); }
public static DictValue merge(DictValue dict1, DictValue dict2) { DictValue dict = new DictValue(dict1.type.GetItemType(), false, dict1); // TODO check type fungibility foreach (KeyValuePair <TextValue, IValue> kvp in ((Dictionary <TextValue, IValue>)dict2)) { dict[kvp.Key] = kvp.Value; } return(dict); }
public IValue Add(Context context, IValue value) { if (value is DictValue) { return(DictValue.merge(this, (DictValue)value)); } else { throw new SyntaxError("Illegal: Dict + " + value.GetType().Name); } }
public IValue Swap(Context context) { DictValue swapped = new DictValue(TextType.Instance, true); foreach (KeyValuePair <TextValue, IValue> kvp in (Dictionary <TextValue, IValue>) this) { IValue key = kvp.Value; if (!(key is TextValue)) { key = new TextValue(key.ToString()); } swapped[(TextValue)key] = kvp.Key; } swapped.mutable = false; return(swapped); }
public bool Equals(Context context, IValue rval) { if (!(rval is DictValue)) { return(false); } DictValue dict = (DictValue)rval; if (this.Count != dict.Count) { return(false); } foreach (TextValue key in this.Keys) { if (!dict.ContainsKey(key)) { return(false); } Object lival = this[key]; if (lival is IExpression) { lival = ((IExpression)lival).interpret(context); } Object rival = dict[key]; if (rival is IExpression) { rival = ((IExpression)rival).interpret(context); } if (lival is IValue && rival is IValue) { if (!((IValue)lival).Equals(context, (IValue)rival)) { return(false); } } else if (!lival.Equals(rival)) { return(false); } } return(true); }
public KVPEnumerator(DictValue dict) { this.src = ((Dictionary <TextValue, IValue>)dict).GetEnumerator(); }