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

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

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

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