Exemplo n.º 1
0
 public bool Contains(XTJsonData item)
 {
     if (item == null)
     {
         item = XTJsonNone.Inst;
     }
     return(this.m_datas.Contains(item));
 }
Exemplo n.º 2
0
 public int IndexOf(XTJsonData item)
 {
     if (item == null)
     {
         item = XTJsonNone.Inst;
     }
     return(this.m_datas.IndexOf(item));
 }
Exemplo n.º 3
0
 public void Insert(int index, XTJsonData item)
 {
     if (item == null)
     {
         item = XTJsonNone.Inst;
     }
     this.m_datas.Insert(index, item);
 }
Exemplo n.º 4
0
 public bool Remove(XTJsonData item)
 {
     if (item == null)
     {
         item = XTJsonNone.Inst;
     }
     return(this.m_datas.Remove(item));
 }
Exemplo n.º 5
0
 public static string AsString(this XTJsonData jdata)
 {
     if (jdata.Type == XTJsonType.String)
     {
         return((string)jdata);
     }
     return(jdata.ToString());
 }
Exemplo n.º 6
0
 public void Add(XTJsonData item)
 {
     if (item == null)
     {
         this.m_datas.Add(XTJsonNone.Inst);
     }
     else
     {
         this.m_datas.Add(item);
     }
 }
Exemplo n.º 7
0
        public void Parse(out XTJsonDict jdict, List <XTJsonComment> doc = null)
        {
            this.EmptyCheck();
            XTJsonCommentParser.Parse(this, doc);
            XTJsonData dict = XTJsonDictParser.Parse(this);

            if (dict == null)
            {
                this.RaiseInvalidException();
            }
            jdict = (XTJsonDict)dict;
        }
Exemplo n.º 8
0
        public static XTJsonData Parse(XTJsonReader reader)
        {
            int chr = reader.CurrUnemptyChar();

            if (chr != '[')
            {
                return(null);
            }
            reader.SkipChar();
            List <XTJsonData> items = new List <XTJsonData>();
            XTJsonData        item  = null;

            do
            {
                chr = reader.CurrUnemptyChar();                                         // 尝试性探测下一个字符
                if (chr == ']')                                                         // 字典结束
                {
                    break;
                }
                else if (chr == ',')                                                                    // 元素结束
                {
                    reader.SkipChar();
                    if (item == null)                                                                   // 错误:{,}
                    {
                        reader.RaiseInvalidException();
                    }
                    chr = reader.CurrUnemptyChar();
                    if (chr == ',')                                                                     // 双逗号分隔错误:[xx, , yy}
                    {
                        reader.RaiseInvalidException();
                    }
                    if (chr == ']')                                                                     // 逗号加括号结束:[xx, yy, ]
                    {
                        break;                                                                          // JSON 本身是不允许的,我这里允许
                    }
                }
                item = reader.ParsePart();
                if (item == null)
                {
                    reader.RaiseInvalidException();
                }
                items.Add(item);
            } while (chr > 0);
            if (reader.NextUnemptyChar() != ']')
            {
                reader.RaiseInvalidException();
            }
            return(new XTJsonList(items));
        }
Exemplo n.º 9
0
 public void Add(XTJsonKeyable key, XTJsonData value)
 {
     if (key == null)
     {
         throw new XTJsonKeyNullException();
     }
     if (value == null)
     {
         this.m_datas.Add(key, XTJsonNone.Inst);
     }
     else
     {
         this.m_datas.Add(key, value);
     }
 }
Exemplo n.º 10
0
        private void WriteJsonData(XTJsonData jdata)
        {
            switch (jdata.Type)
            {
            case XTJsonType.String:
                this.WriteString(jdata);
                break;

            case XTJsonType.Dict:
                this.WriteDict((XTJsonDict)jdata);
                break;

            case XTJsonType.List:
                this.WriteList((XTJsonList)jdata);
                break;

            default:
                this.WriteValue(jdata);
                break;
            }
        }
Exemplo n.º 11
0
        public static long[] AsLongs(this XTJsonData jdata)
        {
            if (jdata.Type == XTJsonType.None)
            {
                return(null);
            }
            XTJsonList jlist = jdata as XTJsonList;

            if (jlist == null)
            {
                throw new XTJsonTypeConvertException(jdata.Type, typeof(long[]));
            }
            long[] items = new long[jlist.Count];
            int    index = -1;

            foreach (XTJsonData item in (XTJsonList)jdata)
            {
                try { items[++index] = (long)item; }
                catch { throw new XTJsonTypeConvertException(jdata.Type, typeof(long[])); }
            }
            return(items);
        }
Exemplo n.º 12
0
        private static DictItem ParseItem(XTJsonReader reader)
        {
            XTJsonData key = reader.ParsePart();

            if (!(key is XTJsonKeyable))                                        // 改数据不能作为字典的 key
            {
                reader.RaiseInvalidException();
            }
            int sp = reader.NextUnemptyChar();

            if (sp != ':')
            {
                reader.RaiseInvalidException();
            }
            XTJsonData value = reader.ParsePart();

            if (value == null)
            {
                reader.RaiseInvalidException();
            }
            return(new DictItem((XTJsonKeyable)key, value));
        }
Exemplo n.º 13
0
 private void WriteValue(XTJsonData jdata)
 {
     this.m_tw.Write(jdata.ToString());
 }
Exemplo n.º 14
0
 private void WriteString(XTJsonData jdata)
 {
     this.m_tw.Write("\"");
     this.m_tw.Write(jdata.ToString());
     this.m_tw.Write("\"");
 }
Exemplo n.º 15
0
 // -------------------------------------------
 // 单值
 // -------------------------------------------
 public static int AsInt(this XTJsonData jdata)
 {
     try { return((int)jdata); }
     catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(int)); }
 }
Exemplo n.º 16
0
 public static long AsLong(this XTJsonData jdata)
 {
     try { return((long)jdata); }
     catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(long)); }
 }
Exemplo n.º 17
0
 public static float AsFloat(this XTJsonData jdata)
 {
     try { return((float)(double)jdata); }
     catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(float)); }
 }
Exemplo n.º 18
0
 public bool TryGetValue(XTJsonKeyable key, out XTJsonData value)
 {
     return(this.m_datas.TryGetValue(key, out value));
 }
Exemplo n.º 19
0
 public static bool AsBool(this XTJsonData jdata)
 {
     try { return((bool)jdata); }
     catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(bool)); }
 }