コード例 #1
0
        public DescribeServicesResult Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeServicesResult describeServicesResult = new DescribeServicesResult();

            describeServicesResult.Services = null;

            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if ((context.IsKey) && (context.CurrentDepth == targetDepth))
                {
                    context.Read();
                    context.Read();

                    if (context.TestExpression("Services", targetDepth))
                    {
                        describeServicesResult.Services = new List <Service>();
                        ServiceUnmarshaller unmarshaller = ServiceUnmarshaller.GetInstance();
                        while (context.Read())
                        {
                            if ((context.IsArrayElement) && (context.CurrentDepth == targetDepth))
                            {
                                describeServicesResult.Services.Add(unmarshaller.Unmarshall(context));
                            }
                            else if (context.IsEndArray)
                            {
                                break;
                            }
                        }
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth <= originalDepth)
                {
                    return(describeServicesResult);
                }
            }


            return(describeServicesResult);
        }
コード例 #2
0
        private static void UnmarshallResult(JsonUnmarshallerContext context, DescribeServicesResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("services", targetDepth))
                {
                    context.Read();

                    if (context.CurrentTokenType == JsonToken.Null)
                    {
                        response.Services = null;
                        continue;
                    }
                    response.Services = new List <Service>();
                    ServiceUnmarshaller unmarshaller = ServiceUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        response.Services.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }