public JMbr(JObj v, string name = null) { this.name = name; type = JType.Object; refv = v; numv = default; }
public void Put(string name, JObj v) { if (counts[level]++ > 0) { Add(','); } if (name != null) { Add('"'); Add(name); Add('"'); Add(':'); } if (v == null) { Add("null"); } else { counts[++level] = 0; // enter Add('{'); v.Write(this); Add('}'); level--; // exit } }
public bool Get(string name, ref JObj v) { if (TryGetValue(name, out var mbr)) { v = mbr; return(true); } return(false); }
public bool Get <D>(string name, ref D v, byte proj = 0x0f) where D : IData, new() { if (TryGetValue(name, out var mbr)) { JObj jobj = mbr; if (jobj != null) { v = new D(); v.Read(jobj); } return(true); } return(false); }
public static D FileToObject <D>(string file, byte proj = 0x0f) where D : IData, new() { try { byte[] bytes = File.ReadAllBytes(file); JObj jo = (JObj) new JsonParser(bytes, bytes.Length).Parse(); if (jo != null) { return(jo.ToObject <D>(proj)); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(default);
public bool Get <D>(string name, ref D[] v, byte proj = 0x0f) where D : IData, new() { if (TryGetValue(name, out var mbr)) { JArr ja = mbr; if (ja != null) { v = new D[ja.Count]; for (int i = 0; i < ja.Count; i++) { JObj jo = ja[i]; D dat = new D(); dat.Read(jo); v[i] = dat; } } return(true); } return(false); }
public void Put(string name, JObj v) { }
public bool Get(string name, ref JObj v) { throw new NotImplementedException(); }
public bool Get(string name, ref long v) { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }
public void Add(JObj elem) { Add(new JMbr(elem)); }
public bool Get <D>(string name, ref D[] v, byte proj = 0x0f) where D : IData, new() { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }
public bool Get(string name, ref ArraySegment <byte> v) { JObj jo = elements[current]; return(jo != null && jo.Get(name, ref v)); }
public void Add(string name, JObj v) { Add <JMbr>(new JMbr(v, name)); }
public bool Get(string name, ref JObj v) { return(false); }
public void Put(string name, JObj v) { throw new NotImplementedException(); }
public static D StringToObject <D>(string v, byte proj = 0x0f) where D : IData, new() { JObj jo = (JObj) new JsonParser(v).Parse(); return(jo.ToObject <D>(proj)); }