void WriteVal(P6any obj) { if (!obj.IsDefined()) { o.Append("null"); } else if (obj.Isa(setting.BoolMO)) { o.Append(Kernel.UnboxAny <int>(obj) != 0 ? "true" : "false"); } else if (obj.Isa(setting.NumMO) || obj.Isa(setting.IntMO) || obj.Isa(setting.RatMO) || obj.Isa(setting.FatRatMO)) { o.Append(Utils.N2S(obj.mo.mro_raw_Numeric.Get(obj))); } else if (obj.Isa(setting.StrMO)) { o.Append('"'); JsyncWriter.AddStringContents(o, Kernel.UnboxAny <string>(obj)); o.Append('"'); } else { WriteObj(obj); } }
public static string ToJsync(P6any obj) { JsyncWriter w = new JsyncWriter(); w.WriteObj(obj); if (w.headerized) { w.o.Append(']'); } return(w.o.ToString()); }
[ImplicitConsts] public static string to_jsync(Constants c, P6any obj) { JsyncWriter w = new JsyncWriter(); w.setting = c.setting; w.WriteObj(obj); if (w.headerized) { w.o.Append(']'); } return(w.o.ToString()); }
internal void WriteObj(P6any obj) { bool comma = false; bool def = obj.IsDefined(); if (def && obj.Isa(setting.HashMO)) { VarHash vh = Kernel.UnboxAny <VarHash>(obj); o.Append('{'); foreach (KeyValuePair <string, Variable> kv in vh) { if (comma) { o.Append(','); } comma = true; o.Append('"'); JsyncWriter.AddStringContents(o, kv.Key); o.Append('"'); o.Append(':'); WriteVal(kv.Value.Fetch()); } o.Append('}'); } else if (def && obj.Isa(setting.ListMO)) { VarDeque iter = obj.mo.mro_raw_iterator.Get(obj); o.Append('['); while (Kernel.IterHasFlat(iter, true)) { if (comma) { o.Append(','); } comma = true; WriteVal(iter.Shift().Fetch()); } o.Append(']'); } else if (JsyncWriter.FailSoft) { o.Append("\"*UNSERIALIZABLE*\""); } else { throw new NieczaException("JSON writer encountered value of type " + obj.mo.name); } }