Example #1
0
 public JMbr(JObj v, string name = null)
 {
     this.name = name;
     type      = JType.Object;
     refv      = v;
     numv      = default;
 }
Example #2
0
 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
     }
 }
Example #3
0
        public bool Get(string name, ref JObj v)
        {
            if (TryGetValue(name, out var mbr))
            {
                v = mbr;
                return(true);
            }

            return(false);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
Example #6
0
        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);
        }
Example #7
0
 public void Put(string name, JObj v)
 {
 }
Example #8
0
 public bool Get(string name, ref JObj v)
 {
     throw new NotImplementedException();
 }
Example #9
0
        public bool Get(string name, ref long v)
        {
            JObj jo = elements[current];

            return(jo != null && jo.Get(name, ref v));
        }
Example #10
0
 public void Add(JObj elem)
 {
     Add(new JMbr(elem));
 }
Example #11
0
        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));
        }
Example #12
0
        public bool Get(string name, ref ArraySegment <byte> v)
        {
            JObj jo = elements[current];

            return(jo != null && jo.Get(name, ref v));
        }
Example #13
0
 public void Add(string name, JObj v)
 {
     Add <JMbr>(new JMbr(v, name));
 }
Example #14
0
 public bool Get(string name, ref JObj v)
 {
     return(false);
 }
Example #15
0
 public void Put(string name, JObj v)
 {
     throw new NotImplementedException();
 }
Example #16
0
        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));
        }