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

            return(false);
        }
Exemple #4
0
        public bool Get <D>(string name, ref D v, short msk = 0xff) 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);
        }
Exemple #5
0
        public static D FileToObject <D>(string file, short proj = 0xff) 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);
Exemple #6
0
        public bool Get <D>(string name, ref D[] v, short msk = 0xff) 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);
        }
Exemple #7
0
 public bool Get(string name, ref JObj v)
 {
     return(false);
 }
Exemple #8
0
 public void Put(string name, JObj v)
 {
 }
Exemple #9
0
        public bool Get(string name, ref long v)
        {
            JObj jo = elements[cur];

            return(jo != null && jo.Get(name, ref v));
        }
Exemple #10
0
 public void Add(JObj el)
 {
     Add(new JMbr(el));
 }
Exemple #11
0
        public bool Get <D>(string name, ref D[] v, short msk = 0xff) where D : IData, new()
        {
            JObj jo = elements[cur];

            return(jo != null && jo.Get(name, ref v));
        }
Exemple #12
0
 public bool Get(string name, ref JObj v)
 {
     throw new NotImplementedException();
 }
Exemple #13
0
        public bool Get(string name, ref ArraySegment <byte> v)
        {
            JObj jo = elements[cur];

            return(jo != null && jo.Get(name, ref v));
        }
Exemple #14
0
        public static D StringToObject <D>(string v, short proj = 0xff) where D : IData, new()
        {
            JObj jo = (JObj) new JsonParser(v).Parse();

            return(jo.ToObject <D>(proj));
        }
Exemple #15
0
 public void Add(string name, JObj v)
 {
     Add <JMbr>(new JMbr(v, name));
 }