コード例 #1
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
        private static object objectParser(JSONParser.Context ctx, Type type)
        {
            JSONParser.forward(ctx);
            if (JSONParser.match(ctx, 'n'))
            {
                if (ctx.pos + 3 > ctx.src.Length)
                {
                    throw new JSONParser.UnexpectedEOFException(ctx);
                }
                if ((int)ctx.src[ctx.pos] != 117 || (int)ctx.src[ctx.pos + 1] != 108 || (int)ctx.src[ctx.pos + 2] != 108)
                {
                    throw new JSONParser.UnexpectedCharacterException(ctx);
                }
                ctx.pos += 3;
                return((object)null);
            }
            object obj = (object)null;

            if ((object)type != null)
            {
                obj = Activator.CreateInstance(type);
            }
            JSONParser.parseObject(ctx, obj);
            return(obj);
        }
コード例 #2
0
ファイル: JSONParser.cs プロジェクト: zunaalabaya/TAC-BOT
        private static bool parseObject(JSONParser.Context ctx, object obj)
        {
            Type type = obj == null ? (Type)null : obj.GetType();

            JSONParser.forward(ctx);
            if (!JSONParser.match(ctx, '{'))
            {
                throw new JSONParser.UnexpectedCharacterException(ctx);
            }
            while (true)
            {
                JSONParser.forward(ctx);
                if (!JSONParser.match(ctx, '}'))
                {
                    if ((int)ctx.src[ctx.pos] == 34)
                    {
                        JSONParser.parseString(ctx);
                        if (ctx.sb.Length > 0)
                        {
                            JSONParser.forward(ctx);
                            if ((int)ctx.src[ctx.pos] == 58)
                            {
                                ++ctx.pos;
                                JSONParser.forward(ctx);
                                FieldInfo fieldInfo = (object)type == null ? (FieldInfo)null : type.GetField(ctx.sb.ToString());
                                if ((object)fieldInfo == null)
                                {
                                    if ((int)ctx.src[ctx.pos] == 34)
                                    {
                                        JSONParser.parseString(ctx);
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 123)
                                    {
                                        JSONParser.parseObject(ctx, (object)null);
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 91)
                                    {
                                        JSONParser.parseArray(ctx, (Type)null);
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 45 || 48 <= (int)ctx.src[ctx.pos] && (int)ctx.src[ctx.pos] <= 57)
                                    {
                                        JSONParser.parseNumber(ctx, false);
                                    }
                                }
                                else
                                {
                                    Type fieldType = fieldInfo.FieldType;
                                    if (fieldType.IsValueType || (object)fieldType == (object)typeof(string))
                                    {
                                        if ((object)fieldType == (object)typeof(int))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)int.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(long))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)long.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(float))
                                        {
                                            JSONParser.parseNumber(ctx, false);
                                            fieldInfo.SetValue(obj, (object)float.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(double))
                                        {
                                            JSONParser.parseNumber(ctx, false);
                                            fieldInfo.SetValue(obj, (object)double.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(short))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)short.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(byte))
                                        {
                                            JSONParser.parseNumber(ctx, true);
                                            fieldInfo.SetValue(obj, (object)byte.Parse(ctx.sb.ToString()));
                                        }
                                        else if ((object)fieldType == (object)typeof(string))
                                        {
                                            JSONParser.parseString(ctx);
                                            fieldInfo.SetValue(obj, (object)ctx.sb.ToString());
                                        }
                                        else
                                        {
                                            goto label_33;
                                        }
                                    }
                                    else if (fieldType.IsArray)
                                    {
                                        if ((int)ctx.src[ctx.pos] == 91 && (int)ctx.src[ctx.pos + 1] == 93)
                                        {
                                            ctx.pos += 2;
                                        }
                                        else
                                        {
                                            Type   elementType = fieldType.GetElementType();
                                            object array       = JSONParser.parseArray(ctx, elementType);
                                            fieldInfo.SetValue(obj, array);
                                        }
                                    }
                                    else if ((int)ctx.src[ctx.pos] == 123 && (int)ctx.src[ctx.pos + 1] == 125)
                                    {
                                        ctx.pos += 2;
                                    }
                                    else
                                    {
                                        object obj1;
                                        if (JSONParser.match(ctx, 'n'))
                                        {
                                            if (ctx.pos + 3 <= ctx.src.Length)
                                            {
                                                if ((int)ctx.src[ctx.pos] == 117 && (int)ctx.src[ctx.pos + 1] == 108 && (int)ctx.src[ctx.pos + 2] == 108)
                                                {
                                                    ctx.pos += 3;
                                                    obj1     = (object)null;
                                                }
                                                else
                                                {
                                                    goto label_45;
                                                }
                                            }
                                            else
                                            {
                                                goto label_42;
                                            }
                                        }
                                        else
                                        {
                                            obj1 = Activator.CreateInstance(fieldType);
                                            JSONParser.parseObject(ctx, obj1);
                                        }
                                        fieldInfo.SetValue(obj, obj1);
                                    }
                                }
                                JSONParser.forward(ctx);
                                if ((int)ctx.src[ctx.pos] == 44)
                                {
                                    ++ctx.pos;
                                }
                                else
                                {
                                    goto label_50;
                                }
                            }
                            else
                            {
                                goto label_8;
                            }
                        }
                        else
                        {
                            goto label_6;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    goto label_53;
                }
            }
            throw new JSONParser.UnexpectedCharacterException(ctx);
label_6:
            throw new JSONParser.InvalidKeyException(ctx);
label_8:
            throw new JSONParser.UnexpectedCharacterException(ctx);
label_33:
            throw new JSONParser.UnsupportedTypeException(ctx);
label_42:
            throw new JSONParser.UnexpectedEOFException(ctx);
label_45:
            throw new JSONParser.UnexpectedCharacterException(ctx);
label_50:
            if ((int)ctx.src[ctx.pos] != 125)
            {
                throw new JSONParser.InvalidCharacterException(ctx);
            }
            ++ctx.pos;
label_53:
            return(true);
        }