private BonArray NextArray() { BonArray b = new BonArray(); while (true) { char c = NextToken(); if (c == ']') { break; } myIndex--; BonValue v = NextValue(); b.Add(v); c = NextToken(); if (c == ']') { break; } if (c != ',') { throw SyntaxError("Array error"); } } return(b); }
private BonArray ReadArray() { BonArray arr = new BonArray(); int count = br.Read7BitEncodedInt(); for (int i = 0; i < count; i++) { arr.Add(Read()); } return(arr); }
public BonDocument ToJson() { BonDocument json = new BonDocument(); json["dlcType"] = (int)dlcType; BonDocument files = new BonDocument(); json["files"] = files; foreach (KeyValuePair <string, FileDesc> p in this.files) { files[p.Key] = p.Value.ToJson(); } if (dependences != null) { BonArray dps = new BonArray(); foreach (string d in dependences) { dps.Add(d); } json["dependences"] = dps; } return(json); }
public static BonValue ToBon(object obj, HashSet <string> fields = null, Type declareType = null) { if (obj == null) { return(BonNull.value); } Type t = obj.GetType(); switch (t.Name) { case "Byte": return((int)(byte)obj); case "SByte": return((int)(sbyte)obj); case "Int16": return((int)(short)obj); case "UInt16": return((int)(ushort)obj); case "Int32": return((int)obj); case "UInt32": return((int)(uint)obj); case "Int64": return((long)obj); case "UInt64": return((long)(ulong)obj); case "Single": return((float)obj); case "Double": return((double)obj); case "Boolean": return((bool)obj); case "String": return((string)obj); case "Byte[]": return((byte[])obj); default: { if (t.IsEnum) { return((int)obj); } break; } } switch (t.Name) { case "List`1": { Type et = t.GetGenericArguments()[0]; BonArray arr = null; arr = new BonArray(); IList list = (IList)obj; int num = list.Count; for (int i = 0; i < num; i++) { arr.Add(ToBon(list[i], fields, et)); } return(arr); } case "Dictionary`2": { Type et = t.GetGenericArguments()[1]; BonDocument doc = null; doc = new BonDocument(); foreach (DictionaryEntry kv in (IDictionary)obj) { if (kv.Key.GetType().IsEnum) { doc[((int)kv.Key).ToString()] = ToBon(kv.Value, fields, et); } else { doc[kv.Key.ToString()] = ToBon(kv.Value, fields, et); } } return(doc); } default: { if (t.IsArray) { Type et = t.GetElementType(); BonArray arr = null; arr = new BonArray(); Array list = (Array)obj; int num = list.Length; for (int i = 0; i < num; i++) { arr.Add(ToBon(list.GetValue(i), fields, et)); } return(arr); } { if (obj is IBon) { return(((IBon)obj).ToBon()); } ClassInfo ci = ClassInfo.Get(t); BonDocument doc = new BonDocument(); if (declareType != null && declareType != t) { doc["_t_"] = t.FullName; } FldInfo[] fis = ci.fields.Values; for (int i = fis.Length; --i >= 0;) { FldInfo fi = fis[i]; if (fields != null && !fields.Contains(fi.name)) { continue; } doc[fi.name] = ToBon(fi.GetValue(obj), fi.subFields); } return(doc); } } } }