Пример #1
0
        protected static List<T> FillArrayWithResponseData<T>(Type clazz, MPAPIResponse response) where T : MPBase
        {
            List<T> resourceArray = new List<T>();
            if (response.JsonObjectResponse != null)
            {
                JArray jsonArray = MPCoreUtils.GetArrayFromJsonElement<T>(response.JsonObjectResponse); 

                if (jsonArray != null)
                {
                    for (int i = 0; i < jsonArray.Count(); i++)
                    {
                        T resource = (T)MPCoreUtils.GetResourceFromJson<T>(clazz, (JObject)jsonArray[i]);

                        resource.DumpLog();

                        resource._lastKnownJson = MPCoreUtils.GetJsonFromResource(resource);
                        resourceArray.Add(resource);
                    }
                }
            } else {
                JArray jsonArray = MPCoreUtils.GetJArrayFromStringResponse<T>(response.StringResponse);
                if (jsonArray != null)
                {
                    for (int i = 0; i < jsonArray.Count(); i++)
                    {
                        T resource = (T)MPCoreUtils.GetResourceFromJson<T>(clazz, (JObject)jsonArray[i]);
                        resource._lastKnownJson = MPCoreUtils.GetJsonFromResource(resource);
                        resourceArray.Add(resource);
                    }
                }
            }
            return resourceArray;
        }
Пример #2
0
        protected static List <T> FillArrayWithResponseData <T>(Type clazz, MPAPIResponse response) where T : MPBase
        {
            List <T> objList = new List <T>();

            if (response.JsonObjectResponse != null)
            {
                JArray arrayFromJsonElement = MPCoreUtils.GetArrayFromJsonElement <T>(response.JsonObjectResponse);
                if (arrayFromJsonElement != null)
                {
                    for (int index = 0; index < arrayFromJsonElement.Count <JToken>(); ++index)
                    {
                        T resourceFromJson = (T)MPCoreUtils.GetResourceFromJson <T>(clazz, (JObject)arrayFromJsonElement[index]);
                        //resourceFromJson.DumpLog();
                        resourceFromJson._lastKnownJson = MPCoreUtils.GetJsonFromResource <T>(resourceFromJson);
                        objList.Add(resourceFromJson);
                    }
                }
            }
            else
            {
                JArray fromStringResponse = MPCoreUtils.GetJArrayFromStringResponse <T>(response.StringResponse);
                if (fromStringResponse != null)
                {
                    for (int index = 0; index < fromStringResponse.Count <JToken>(); ++index)
                    {
                        T resourceFromJson = (T)MPCoreUtils.GetResourceFromJson <T>(clazz, (JObject)fromStringResponse[index]);
                        resourceFromJson._lastKnownJson = MPCoreUtils.GetJsonFromResource <T>(resourceFromJson);
                        objList.Add(resourceFromJson);
                    }
                }
            }
            return(objList);
        }