public bool Contains(XTJsonData item) { if (item == null) { item = XTJsonNone.Inst; } return(this.m_datas.Contains(item)); }
public int IndexOf(XTJsonData item) { if (item == null) { item = XTJsonNone.Inst; } return(this.m_datas.IndexOf(item)); }
public void Insert(int index, XTJsonData item) { if (item == null) { item = XTJsonNone.Inst; } this.m_datas.Insert(index, item); }
public bool Remove(XTJsonData item) { if (item == null) { item = XTJsonNone.Inst; } return(this.m_datas.Remove(item)); }
public static string AsString(this XTJsonData jdata) { if (jdata.Type == XTJsonType.String) { return((string)jdata); } return(jdata.ToString()); }
public void Add(XTJsonData item) { if (item == null) { this.m_datas.Add(XTJsonNone.Inst); } else { this.m_datas.Add(item); } }
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; }
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)); }
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); } }
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; } }
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); }
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)); }
private void WriteValue(XTJsonData jdata) { this.m_tw.Write(jdata.ToString()); }
private void WriteString(XTJsonData jdata) { this.m_tw.Write("\""); this.m_tw.Write(jdata.ToString()); this.m_tw.Write("\""); }
// ------------------------------------------- // 单值 // ------------------------------------------- public static int AsInt(this XTJsonData jdata) { try { return((int)jdata); } catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(int)); } }
public static long AsLong(this XTJsonData jdata) { try { return((long)jdata); } catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(long)); } }
public static float AsFloat(this XTJsonData jdata) { try { return((float)(double)jdata); } catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(float)); } }
public bool TryGetValue(XTJsonKeyable key, out XTJsonData value) { return(this.m_datas.TryGetValue(key, out value)); }
public static bool AsBool(this XTJsonData jdata) { try { return((bool)jdata); } catch (Exception) { throw new XTJsonTypeConvertException(jdata.Type, typeof(bool)); } }