public override bool Addition(StackContext sctx, PValue leftOperand, PValue rightOperand, out PValue result) { result = null; if (leftOperand.Type is HashPType && rightOperand.Type is HashPType) { var pvht1 = (PValueHashtable) leftOperand.Value; var pvht2 = (PValueHashtable) rightOperand.Value; var pvht = new PValueHashtable(pvht1.Count + pvht2.Count); foreach (var pair in pvht1) pvht.Add(pair); foreach (var pair in pvht2) pvht.AddOverride(pair); result = (PValue) pvht; } return result != null; }
public override bool TryConstruct(StackContext sctx, PValue[] args, out PValue result) { if (sctx == null) throw new ArgumentNullException("sctx"); if (args == null) args = new PValue[] {}; result = null; for (var i = 0; i < args.Length; i++) { if (args[i] == null) args[i] = Null.CreatePValue(); } var argc = args.Length; PValueHashtable pvht = null; if (argc == 0) { pvht = new PValueHashtable(); } else if (args[0].IsNull) { pvht = new PValueHashtable(); } else if (argc > 0) { var arg0 = args[0]; if (arg0.Type == Hash || (arg0.Type is ObjectPType && arg0.Value is IDictionary<PValue, PValue>)) { pvht = new PValueHashtable((IDictionary<PValue, PValue>) arg0.Value); } else if (arg0.Type == Int) { pvht = new PValueHashtable((int) arg0.Value); } } if (pvht != null) result = new PValue(pvht, this); return result != null; }
protected override bool InternalConvertFrom( StackContext sctx, PValue subject, bool useExplicit, out PValue result) { if (sctx == null) throw new ArgumentNullException("sctx"); if (subject == null) throw new ArgumentNullException("subject"); result = null; PValueHashtable pvht = null; var sT = subject.Type; if (sT is ObjectPType) { var os = subject.Value; var o_pvht = os as PValueHashtable; if (o_pvht != null) pvht = o_pvht; else { var id = os as IDictionary<PValue, PValue>; if (id != null) pvht = new PValueHashtable(id); else { var pvkvp = os as PValueKeyValuePair; if (pvkvp != null) { pvht = new PValueHashtable(1); pvht.Add(pvkvp); } else if (os is KeyValuePair<PValue, PValue>) { pvht = new PValueHashtable(1); pvht.Add((KeyValuePair<PValue, PValue>) os); } } } } else if (sT == Null) pvht = new PValueHashtable(); if (pvht != null) result = new PValue(pvht, this); return result != null; }
public override bool TryStaticCall( StackContext sctx, PValue[] args, PCall call, string id, out PValue result) { if (sctx == null) throw new ArgumentNullException("sctx"); if (args == null) args = new PValue[] {}; if (id == null) id = ""; result = null; for (var i = 0; i < args.Length; i++) { if (args[i] == null) args[i] = Null.CreatePValue(); } PValueHashtable pvht; switch (id.ToLowerInvariant()) { case "create": //Create(params KeyValuePair[] pairs) pvht = new PValueHashtable(args.Length); foreach (var arg in args) { PValueKeyValuePair pairArg; if (_tryConvertToPair(sctx, arg, out pairArg)) pvht.AddOverride(pairArg); } result = new PValue(pvht, this); break; case "createFromArgs": if (args.Length%2 != 0) break; pvht = new PValueHashtable(args.Length/2); for (var i = 0; i < args.Length; i += 2) pvht.AddOverride(args[i], args[i + 1]); result = new PValue(pvht, this); break; default: return PValueHashtable.ObjectType.TryStaticCall(sctx, args, call, id, out result); } return result != null; }